我正在尝试使用Shiny获取dataTables TableTools和其他扩展。我找到了一个网站解释如何做:
https://gist.github.com/bearloga/8327428
但是我无法正常工作。 addResourcePath在我的脚本中不起作用,因此我从完整路径进行采购。即使到那时,似乎采购DataTables和扩展也没有任何作用,而且我只得到了一个基本表,而没有TableTools或任何其他扩展。我知道tags$script
条目正在工作,因为如果使窗口足够小,则会从下面的HTML收到Screen too small
警告。
有任何想法吗?
#### 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.com/libraries/datatables处找到data.table 1.9.4的表。在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")
)
)
)
)
)
})
)
关于javascript - 具有TableTools和其他扩展功能的R Shiny 数据表,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24510671/