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.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.
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")
)
)
)
)
)
})
########################################
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…