5

I have an R Shiny app and one of the output elements is a databale. I use the following code to display Buttons like Copy, Excel, Print:

df <- datatable(df, 
                  rownames= FALSE,
                  filter = 'top',
                  extensions = 'Buttons', 
                  options = list(scrollX = TRUE
                                 , pageLength = 5
                                 , dom = 'Blfrtip'
                                 ,buttons = c('copy', 'csv', 'excel', 'pdf', 'print')
                                 )) 

The table has about 2000 rows. Everything works great, but if I click on CSV it only exports the rows visualized on the screen. Is there anything that could be done to make this CSV button exporting all the data in Excel? Many thanks

Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
Angelo
  • 1,594
  • 5
  • 17
  • 50

1 Answers1

5

Set server = FALSE in the renderDT function:

output[["zzz"]] <- renderDT({
  datatable(......)
}, server = FALSE)
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
  • 1
    This is absolutely perfect. Please, just out of curiosity, may I ask how I could have found this solution alone? Like what specific documentation page did you check to figure it out? Thank you! – Angelo Nov 24 '20 at 18:50
  • 1
    @Angelo you could look up https://rstudio.github.io/DT/server.html As I have come to understand it, when using datatables in complex apps, you start to realize there is more to reactivity than just the interaction between users and server, but also how the browser "sees" the info displayed in the datatable. Turning on and off the server argument let's you control who is rendering the info: shiny's server or the client. – David Jorquera Nov 24 '20 at 18:55
  • 1
    @Angelo simply in the doc: `?renderDT`. – Stéphane Laurent Nov 25 '20 at 15:33