Use TableTools for DataTables in R Shiny for renderDataTable

后端 未结 1 600
粉色の甜心
粉色の甜心 2021-02-06 09:17

For this question, I am using the R Shiny tutorial example found here:

http://rstudio.github.io/shiny/tutorial/#datatables

Running the code on this tutorial rend

1条回答
  •  生来不讨喜
    2021-02-06 09:54

    You need to link to the correct library versions. Links 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

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

    enter image description here

    0 讨论(0)
提交回复
热议问题