从闪亮的renderDataTable中保存 [英] Saving from Shiny renderDataTable

查看:206
本文介绍了从闪亮的renderDataTable中保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题以前已被问过 R数据表与TableTools等的数据扩展程序在R Shiny中为DataTable使用TableTools renderDataTable ,但目前我正在努力获取TableTools的演示,以从闪亮的应用程序下载csv或xls。该按钮似乎工作,csv / xls选项可用,但没有任何反应。我唯一可以想到的是将数据表版本从1.9.4更新为1.10.1,但仍然没有。所有其他路径都是最新的,除非我犯了一些愚蠢的错误。谢谢。



$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ (ui = basicPage(
h1('Diamonds DataTable with TableTools'),
tagList(
singleton(tags $ head(tags $ script(src ='// cdnjs.cloudflare.com/ ajax / libs / datatables / 1.9.4 / jquery.dataTables.min.js',type ='text / javascript'))),
singleton(tags $ head(tags $ script(src ='// cdnjs .cloudflare.com / ajax / libs / datatables-tabletools / 2.1.5 / js / TableTools.min.js',type ='text / javascript'))),
singleton(tags $ head(tags $ script (src ='// cdnjs.cloudflare.com/ajax/libs/datatables-tabletools/2.1.5/js/ZeroClipboard.min.js',type='text/javascript'))),
singleton(标签$ head(tags $ link(href ='// cdnjs.cloudflare.com/ajax/libs/datatables-tabletools/2.1.5/css/TableTools.min.css',rel='stylesheet',type='text / css')))
singleton(标签$ script(HTML(if(window.innerHeight< 400)alert('Screen too small');)))
),
dataTabl eOutput(mytable)

,server = function(input,output){
输出$ mytable = renderDataTable({
diamonds [,1:6]
},options = list(
sDom='T<clear> lfrtip',
oTableTools= list(
sSwfPath=//cdnjs.cloudflare .com / ajax / libs / datatables-tabletools / 2.1.5 / swf / copy_csv_xls.swf,
aButtons=列表(
copy,
print,
list(sExtends=collection,
sButtonText=Save,
aButtons= c(csv,xls)





})


解决方案

在倾倒之后,​​我发现了我的初始错误。令人尴尬的是,主要的问题是我正在试图直接从rstudio推出闪亮的应用程序。我知道这是不可能的,因为rstudio没有闪光灯。因此,最初的解决方案是简单地运行应用程序,然后在安装了Flash的浏览器中打开它。保存按钮可以正常工作,我可以保存已过滤的数据集。



然而,在我的努力期间,我发现了一些简化,其他人可能会发现有用。



下一个版本的闪光将使用更近的1.10.2数据表。您可以从 github页面下载当前的开发版本。这样可以在更新其他源文件的链接后,省略zeroclipboard文件。以下是我在浏览器中打开最新的闪亮包的最终代码。请注意,DataTables 1.10.x已经转换为camelCase符号的符号略有变化。 此处找到旧符号的封面。




库(ggplot2)
runApp(
list(ui = basicPage(
h1('Diamonds DataTable with TableTools'),
tagList(
singleton(tags $ head(tags $ script(src ='// cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js' type ='text / javascript'))),
singleton(tags $ head(tags $ script(src ='// cdn.datatables.net/tabletools/2.2.2/js/dataTables.tableTools.min。 js',type ='text / javascript'))),
singleton(tags $ head(tags $ link(href ='// cdn.datatables.net/tabletools/2.2.2/css/dataTables.tableTools 。
singleton(tags $ script(HTML(if(window.innerHeight< 400)alert('Screen too small' )$)
dataTableOutput(mytable)

,server = function(输入,输出){
输出$ mytable = renderDa taTable({
diamonds [,1:6]
},options = list(
dom='T<clear> lfrtip',
oTableTools = list(
sSwfPath=//cdnjs.cloudflare.com/ajax/libs/datatables-tabletools/2.1.5/swf/copy_csv_xls.swf,
aButtons= list(
copy,
print,
list(sExtends=collection,
sButtonText=Save,
aButtons= c (csv,xls)





})

编辑



在TableTools更新之后,接口已更改为0.1.5x。您现在可以使用按钮扩展程序。 注意 - 这仍然(3/29/16)要求用户从 github 直到作者认为更新足以推动到CRAN。

 库(闪亮)
库(DT)
库(ggplot2)

runApp(
list(ui = basicPage(
h1('Diamonds DataTable with DT'))
dataTableOutput(mytable )

,server = function(input,output){
输出$ mytable = renderDataTable({
diamonds [,1:6]
},
extensions ='Buttons',
options = list(
dom='T<clear> lBfrtip',
buttons = list('copy','csv ','excel','pdf','print')


})


This question has been asked previously R shiny dataTables with TableTools and other extensions and Use TableTools for DataTables in R Shiny for renderDataTable but I am currently struggling getting this demonstration of TableTools to download the csv or xls from a shiny app. The button appears to work and the csv/xls option is available but nothing happens. The only thing I could think of was updating the datatables version from 1.9.4 to 1.10.1 but still nothing. All the other paths are up to date unless I am making some silly mistake. Thank you.

library(shiny)
library(ggplot2)
runApp(
  list(ui = basicPage(
    h1('Diamonds DataTable with TableTools'),
    tagList(
      singleton(tags$head(tags$script(src='//cdnjs.cloudflare.com/ajax/libs/datatables/1.9.4/jquery.dataTables.min.js',type='text/javascript'))),
      singleton(tags$head(tags$script(src='//cdnjs.cloudflare.com/ajax/libs/datatables-tabletools/2.1.5/js/TableTools.min.js',type='text/javascript'))),
      singleton(tags$head(tags$script(src='//cdnjs.cloudflare.com/ajax/libs/datatables-tabletools/2.1.5/js/ZeroClipboard.min.js',type='text/javascript'))),
      singleton(tags$head(tags$link(href='//cdnjs.cloudflare.com/ajax/libs/datatables-tabletools/2.1.5/css/TableTools.min.css',rel='stylesheet',type='text/css'))),
      singleton(tags$script(HTML("if (window.innerHeight < 400) alert('Screen too small');")))
    ),
    dataTableOutput("mytable")
  )
  ,server = function(input, output) {
    output$mytable = renderDataTable({
      diamonds[,1:6]
    }, options = list(
      "sDom" = 'T<"clear">lfrtip',
      "oTableTools" = list(
        "sSwfPath" = "//cdnjs.cloudflare.com/ajax/libs/datatables-tabletools/2.1.5/swf/copy_csv_xls.swf",
        "aButtons" = list(
          "copy",
          "print",
          list("sExtends" = "collection",
               "sButtonText" = "Save",
               "aButtons" = c("csv","xls")
          )
        )
      )
    )
    )
  })
)

解决方案

After pouring over this, I have discovered my initial error. Embarrassingly, the primary issue was that I was trying to save directly from the rstudio launch of the shiny app. I have since learned that this is impossible because rstudio does not have flash. As such, the initial solution was to simply run the app and then open it in a browser with flash installed. The save button then works appropriately and I can save a filtered dataset.

However, during my efforts I have discovered some simplification that others may find useful.

The next version of shiny will use the more recent 1.10.2 DataTables. You can download the current dev version from the github page. This allows one to omit the zeroclipboard file after updating the links for the other source files. Below is the final code I have found works when opened in a browser with the most recent shiny package. Please note, the slight change in notation as the DataTables 1.10.x has converted to camelCase notation. Coversions from the old notation are found here.

library(shiny)
library(ggplot2)
runApp(
  list(ui = basicPage(
    h1('Diamonds DataTable with TableTools'),
    tagList(
      singleton(tags$head(tags$script(src='//cdn.datatables.net/1.10.2/js/jquery.dataTables.min.js',type='text/javascript'))),
      singleton(tags$head(tags$script(src='//cdn.datatables.net/tabletools/2.2.2/js/dataTables.tableTools.min.js',type='text/javascript'))),
      singleton(tags$head(tags$link(href='//cdn.datatables.net/tabletools/2.2.2/css/dataTables.tableTools.css',rel='stylesheet',type='text/css'))),
      singleton(tags$script(HTML("if (window.innerHeight < 400) alert('Screen too small');")))
    ),
    dataTableOutput("mytable")
  )
  ,server = function(input, output) {
    output$mytable = renderDataTable({
      diamonds[,1:6]
    }, options = list(
      "dom" = 'T<"clear">lfrtip',
      "oTableTools" = list(
        "sSwfPath" = "//cdnjs.cloudflare.com/ajax/libs/datatables-tabletools/2.1.5/swf/copy_csv_xls.swf",
        "aButtons" = list(
          "copy",
          "print",
          list("sExtends" = "collection",
               "sButtonText" = "Save",
               "aButtons" = c("csv","xls")
          )
        )
      )
    )
    )
  })
)

EDIT

As of DT 0.1.5x the interface has changed following the TableTools updates. You now use the Buttons extension. Note - this still (3/29/16) requires the user to install from github until the author deems the updates sufficient for pushing to CRAN.

library(shiny)
library(DT)
library(ggplot2)

runApp(
  list(ui = basicPage(
    h1('Diamonds DataTable with DT'),
    dataTableOutput("mytable")
  )
  ,server = function(input, output) {
    output$mytable = renderDataTable({
      diamonds[,1:6]
    }, 
    extensions = 'Buttons',
    options = list(
      "dom" = 'T<"clear">lBfrtip',
      buttons = list('copy', 'csv', 'excel', 'pdf', 'print')
    )
    )
  })
)

这篇关于从闪亮的renderDataTable中保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆