具有桌面工具和其他扩展的闪亮的数据表

时间:2022-04-21 12:20:17

I am trying to get dataTables TableTools and other extensions working with Shiny. I found a website explaining how to do it:

我正在尝试获取dataTables的TableTools和其他有光泽的扩展。我找到一个网站,解释怎么做:

https://gist.github.com/bearloga/8327428

https://gist.github.com/bearloga/8327428

But I can't get it to work. addResourcePath would not work in my script, so I am sourcing from the full path instead. Even then, it seems like sourcing the DataTables and extensions has no effect, and I only get a basic table without the TableTools or any other extensions working. I know the tags$script entries are working because if I make the window small enough, I get the Screen too small warning from the HTML below.

但是我不能让它工作。addResourcePath在我的脚本中不能工作,所以我从完整的路径中寻找。即便如此,似乎查找数据和扩展也没有任何效果,而且我只获得了一个基本的表,而没有使用表工具或任何其他扩展。我知道$script条目的标签是有效的,因为如果我使窗口足够小,我就会从下面的HTML中得到一个很小的警告。

Any ideas?

什么好主意吗?

#### ui.R
suppressWarnings(suppressPackageStartupMessages(library("ggplot2", lib.loc="/opt/thirdparty/R/R-3.1.0/lib64/R/library")))
shinyUI = basicPage(
    h1('Diamonds DataTable with TableTools'),
    tagList(
    singleton(tags$head(tags$script(src='/opt/development/tools/webdev/shiny/datatables/DataTables-1.10.0/media/js/jquery.dataTables.js',type='text/javascript'))),
    singleton(tags$head(tags$script(src='/opt/development/tools/webdev/shiny/datatables/TableTools-2.2.1/js/dataTables.tableTools.js',type='text/javascript'))),
    singleton(tags$head(tags$script(src='/opt/development/tools/webdev/shiny/datatables/ColReorder-1.1.1/js/dataTables.colReorder.js',type='text/javascript'))),
    singleton(tags$head(tags$link(href='/opt/development/tools/webdev/shiny/datatables/TableTools-2.2.1/css/dataTables.tableTools.css',rel='stylesheet',type='text/css'))),
    singleton(tags$script(HTML("if (window.innerHeight < 400) alert('Screen too small');")))
    ),
    dataTableOutput("mytable")
)
########################################

### server.R
shinyServer(function(input, output) {
    output$mytable = renderDataTable({
        diamonds[,1:6]
    }, options = list(
           "sDom" = 'T<"clear">lfrtip',
           "oTableTools" = list(
                        "sSwfPath" = "/opt/development/tools/webdev/shiny/datatables/TableTools-2.2.1/swf/copy_csv_xls.swf",
            "aButtons" = list(
                "copy",
                "print",
                list("sExtends" = "collection",
                     "sButtonText" = "Save",
                     "aButtons" = c("csv","xls")
                )
            )
        )
    )
        )
})
########################################

1 个解决方案

#1


2  

You need to link to the correct library versions. Lins 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")
          )
        )
      )
    )
    )
  })
)

具有桌面工具和其他扩展的闪亮的数据表

#1


2  

You need to link to the correct library versions. Lins 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")
          )
        )
      )
    )
    )
  })
)

具有桌面工具和其他扩展的闪亮的数据表