0

'Hello!

I try to download a workbook into a zip file through a shiny application. How can I do that ?

Here is my code :

library("shiny")
library("openxlsx")

ui <- fluidPage(
  downloadButton("dlmW", "Download data")
)

server <- function(input, output) {
  
output$dlmW <- downloadHandler(
  
  filename = function() { 
    paste0("Test_",Sys.Date(),".xlsx")},
  
  content = function(file) {
      
    wb <- createWorkbook()
    
    # One sheet per table
    addWorksheet(wb, "test")
 
    writeData(wb, 
              sheet="test", 
              iris,
              startRow = 2, 
              startCol = 1,
              withFilter = TRUE,
              colNames = TRUE
    )
    
    saveWorkbook(wb, file = file, overwrite = TRUE)
    
  }
)
}

shinyApp(ui = ui, server = server)

I would like to download the xlsx file into a zip file, without saving it into my project directory.

I tried to use the zip function but I don't know how to use it with a workbook.

Thank you very much for your help !

JoGG
  • 23
  • 3

0 Answers0