使用TableTools为DataTables在R闪亮的renderDataTable。

时间:2022-04-15 14:27:56

For this question, I am using the R Shiny tutorial example found here:

对于这个问题,我使用了在这里找到的R闪亮的教程示例:

http://rstudio.github.io/shiny/tutorial/#datatables

http://rstudio.github.io/shiny/tutorial/的datatable

Running the code on this tutorial renders the application at the following URL

运行本教程中的代码将在以下URL中呈现应用程序。

http://glimmer.rstudio.com/yihui/12_datatables/

http://glimmer.rstudio.com/yihui/12_datatables/

What I would like to know is, once that data table is rendered, we can search it using the functionality built into the renderDataTable() function in R Shiny, but is it possible to download the data you have filtered to using the renderDataTable() function?

我想知道的是,一旦数据表被呈现,我们就可以使用内置在R中的renderDataTable()函数中的功能来搜索它,但是是否可以下载您已经过滤过的数据来使用renderDataTable()函数?

For instance, if in the data table search bar I type, "Very Good," only the records in the "cut" field which read "Very Good" are displayed. How would I then download that data set?

例如,如果在data table search bar I类型中,“非常好”,只有“cut”字段中的记录显示为“非常好”。我如何下载该数据集?

How would I invoke the TableTools.js copy, print, save, etc buttons into this code?

我将如何调用TableTools。js复制,打印,保存,等等按钮到这个代码中?

Thank you!

谢谢你!

1 个解决方案

#1


3  

You need to link to the correct library versions. Links to data.table 1.9.4 can be found at http://cdnjs.com/libraries/datatables . Links to tabletools 2.1.5 at http://cdnjs.com/libraries/datatables-tabletools

您需要链接到正确的库版本。链接数据。表1.9.4可以在http://cdnjs.com/libraries/datatables上找到。在http://cdnjs.com/libraries/datatables-tabletools中链接到tabletools 2.1.5。

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")
          )
        )
      )
    )
    )
  })
)

使用TableTools为DataTables在R闪亮的renderDataTable。

#1


3  

You need to link to the correct library versions. Links to data.table 1.9.4 can be found at http://cdnjs.com/libraries/datatables . Links to tabletools 2.1.5 at http://cdnjs.com/libraries/datatables-tabletools

您需要链接到正确的库版本。链接数据。表1.9.4可以在http://cdnjs.com/libraries/datatables上找到。在http://cdnjs.com/libraries/datatables-tabletools中链接到tabletools 2.1.5。

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")
          )
        )
      )
    )
    )
  })
)

使用TableTools为DataTables在R闪亮的renderDataTable。