R shiny datatable extension "Buttons" - how to export the whole table to excel?
Asked Answered
F

1

6

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

Fulminate answered 24/11, 2020 at 16:57 Comment(0)
J
6

Set server = FALSE in the renderDT function:

output[["zzz"]] <- renderDT({
  datatable(......)
}, server = FALSE)
Jaquelin answered 24/11, 2020 at 17:49 Comment(3)
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!Fulminate
@Fulminate you could look up 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.Trimmer
@Fulminate simply in the doc: ?renderDT.Antagonism

© 2022 - 2024 — McMap. All rights reserved.