Buttons: download button with scroller downloads only few rows

风流意气都作罢 提交于 2020-01-02 02:53:07

问题


I am handling tables with more than 100 000 rows and using DT package (development version 0.1.56) to visualize it in Shiny App.

Furthermore I am using DT Extensions as: Buttons, to download the data in different formats. However while Scroller extension is as well activated, i am able only to download few rows (not all data).

Sample code:

library("shiny")
library("DT")

shinyApp(
  ui = fluidPage(DT::dataTableOutput('tbl')),
  server = function(input, output) {
    output$tbl = DT::renderDataTable(
      iris,extensions=c("Buttons",'Scroller'),options = list(dom = 'Bfrtip',
                                               buttons = c('copy', 'csv', 'excel', 'pdf', 'print'),scrollY = 50,
                                               scroller = TRUE
      ))
  }
)

Additionally if i run only this part of the code in R and get the datatable in the viewer, i am able to copy etc. all rows, how it is even possible?

library("DT")
datatable(
  iris,
  extensions = 'Buttons', options = list(
    dom = 'Bfrtip',
    buttons = c('copy', 'csv', 'excel', 'pdf', 'print')
  )
)

I have tried different approaches:

  1. Changing scrollY = ... in the option list -> it is working but the number of scrollY has to be huge to actually display all data rows so it could be downloaded fully --> not good approach, as my data comes from Database, i obtain different number of rows plus it makes the app extremally slow

  2. Using pageLength option: pageLength = ..., lengthMenu=c(..,..,..,..)

However the option to choose is not displayed at all...

Any ideas how i can solve this problem?

  • I am aware about downloadHandler() approach, however i would prefer to do it through DT as the available Extensions give nice and elegant way, which allows to download the data in different formats at once such as pdf, excel,csv and print.

**I have seen already the same question:

Download button downloads only 145 rows in DataTables with Scroller

but it has not been answered in the meaning of DT package

Thanks in advance


回答1:


The issue is that when server=TRUE only the data being displayed is being sent to the client. Setting server=FALSE renders all the DT stuff in the client so all the data is there.




回答2:


It is indeed server = TRUE that does the trick.

Here is the code since some people like me might put the argument in the wrong place.

library("shiny")
library("DT")

shinyApp(
  ui = fluidPage(DT::dataTableOutput('tbl')),
  server = function(input, output) {
    output$tbl = DT::renderDataTable(server = FALSE,{
      DT::datatable(iris,
                    extensions=c("Buttons",'Scroller'),
                    options = list(dom = 'Bfrtip',
                                   buttons = c('copy', 'csv', 
                                               'excel', 'pdf', 
                                               'print'),
                                   scrollY = 50,
                                   scroller = TRUE)
      )
    })
  }
)


来源:https://stackoverflow.com/questions/38477345/buttons-download-button-with-scroller-downloads-only-few-rows

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!