一些注意事项:
当前的 data.table 版本与闪亮的 atm 不兼容。我们需要1.9.4
版本。然后我们还需要预1.1.0
的版本colvis
。不幸的是,这引用了旧版本的 jQuery,它发出了对jQuery.browser
。所以参考这个jQuery.browser
需要删除它出现在第 856 到 859 行。 sDom 属性也有点棘手,它没有出现在新的 data.table 中,被替换为dom
。文档位于http://legacy.datatables.net/usage/options#sDom。我们将 colVis 内容添加到class="cvclear"
使用这个片段<"cvclear"C>
。将其放在顶部是通过将其放在开头来完成的sDom
陈述。这是可行的,但是我们需要将其右对齐。通常这可以通过添加来完成align = "right"
到班级,但因为班级是通过sDom
调用时我们必须使用 HTML5 csstext-align:right
。我们添加这个使用tags$style
.
所以上面应该允许我们使用colVis
与目前的闪亮。当shiny升级到data.table时1.10.0
那么我们应该能够使用当前的colVis
插件文件和修复希望是不必要的。
以下对我有用:
ui.R
# get the colVis js file and delete lines
library(RCurl)
write(getURL("https://raw.githubusercontent.com/openMF/mifosx-community-apps/master/IndividualLendingGeneralJavaScript/resources/libs/DataTables-1.9.4/extras/ColVis/media/js/ColVis.js")
, file = 'www/colvis.js')
tf <- readLines("www/colvis.js")[-c(856:859)]
write(tf, file = "www/colvis.js")
shinyUI({
pageWithSidebar(
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='//cdn.datatables.net/colreorder/1.1.1/js/dataTables.colReorder.min.js',type='text/javascript'))),
singleton(tags$head(tags$script(src='colvis.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$head(tags$link(href='https://raw.githubusercontent.com/openMF/mifosx-community-apps/master/IndividualLendingGeneralJavaScript/resources/libs/DataTables-1.9.4/extras/ColVis/media/css/ColVis.css',rel='stylesheet',type='text/css'))),
singleton(tags$script(HTML("if (window.innerHeight < 400) alert('Screen too small');"))),
singleton(tags$head(tags$link(href='https://raw.githubusercontent.com/DataTables/ColVis/18b52dfdd7255ffe96a92aadc16cadd70e3e174a/media/css/ColVis.css',rel='stylesheet',type='text/css')))
, tags$head(
tags$style(HTML("
.cvclear{
text-align:right}")
)
)
),
dataTableOutput("mytable")
)
})
server.R
library(shiny)
library(ggplot2)
shinyServer(function(input, output, session) {
output$mytable = renderDataTable({
diamonds[,1:6]
}, options = list(
"sDom" = 'RMD<"cvclear"C><"clear"T>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")
)
)
)
)
)
}
)
您可以在以下位置查看该应用程序:
http://128.199.255.233:3838/userApps/john/cvtestapp/