带有 TableTools 和其他扩展的 R 闪亮数据表

编程入门 行业动态 更新时间:2024-10-24 08:32:26
本文介绍了带有 TableTools 和其他扩展的 R 闪亮数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让 dataTables、TableTools 和其他扩展与 Shiny 一起使用.我找到了一个解释如何操作的网站:

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

https://gist.github/bearloga/8327428

但我无法让它工作.addResourcePath 在我的脚本中不起作用,所以我从完整路径中采购.即便如此,似乎采购 DataTables 和扩展也没有效果,我只得到一个基本表,没有 TableTools 或任何其他扩展工作.我知道 tags$script 条目正在工作,因为如果我使窗口足够小,我会从下面的 HTML 中收到 Screen too small 警告.

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.

有什么想法吗?

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

推荐答案

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

You need to link to the correct library versions. Lins to data.table 1.9.4 can be found at http://cdnjs/libraries/datatables . Links to tabletools 2.1.5 at http://cdnjs/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/ajax/libs/datatables/1.9.4/jquery.dataTables.min.js',type='text/javascript'))),
      singleton(tags$head(tags$script(src='//cdnjs.cloudflare/ajax/libs/datatables-tabletools/2.1.5/js/TableTools.min.js',type='text/javascript'))),
      singleton(tags$head(tags$script(src='//cdnjs.cloudflare/ajax/libs/datatables-tabletools/2.1.5/js/ZeroClipboard.min.js',type='text/javascript'))),
      singleton(tags$head(tags$link(href='//cdnjs.cloudflare/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/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 和其他扩展的 R 闪亮数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-28 04:52:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/717707.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据表   TableTools

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!