在R Shiny for renderDataTable中为DataTable使用TableTools [英] Use TableTools for DataTables in R Shiny for renderDataTable

查看:652
本文介绍了在R Shiny for renderDataTable中为DataTable使用TableTools的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于这个问题,我正在使用R Shiny教程示例:

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

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

运行本教程中的代码会呈现应用程序在以下网址

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

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

我想知道的是,一旦呈现了数据表,我们可以使用renderDataTable中内置的功能)功能在R Shiny中,但是可以使用renderDataTable()函数下载已过滤的数据吗?

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?

例如,如果在数据表搜索栏我输入很好,只显示切字段中记录非常好的记录。我如何下载该数据集?

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?

我如何将TableTools.js复制,打印,保存等按钮调用到此代码?

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

谢谢!

推荐答案

您需要链接到正确的库版本。 data.table 1.9.4的链接可以在 http://cdnjs.com/libraries/datatables。 tabletools的链接2.1.5在 http://cdnjs.com/libraries/datatables-tabletools

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

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

这篇关于在R Shiny for renderDataTable中为DataTable使用TableTools的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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