Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Buttons: download button with scroller downloads only few rows

Tags:

r

dt

shiny

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

like image 473
Mal_a Avatar asked Jul 20 '16 09:07

Mal_a


2 Answers

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)
      )
    })
  }
)
like image 118
takje Avatar answered Oct 16 '22 10:10

takje


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.

like image 15
Carl Avatar answered Oct 16 '22 09:10

Carl