Shiny: download zip archive
You are using <-
inside the downloadHandler function and should be using =
. Also you may need to define the contentType
:
library(shiny)
runApp(
list(server = function(input, output) {
output$downloadData <- downloadHandler(
filename = function() {
paste("output", "zip", sep=".")
},
content = function(fname) {
fs <- c()
tmpdir <- tempdir()
setwd(tempdir())
for (i in c(1,2,3,4,5)) {
path <- paste0("sample_", i, ".csv")
fs <- c(fs, path)
write(i*2, path)
}
zip(zipfile=fname, files=fs)
},
contentType = "application/zip"
)
}
, ui = fluidPage(
titlePanel(""),
sidebarLayout(
sidebarPanel(
downloadButton("downloadData", label = "Download")
),
mainPanel(h6("Sample download", align = "center"))
)
))
)