My application runs smoothly in Rstudio, both in the viewer and also the browser (locally, using Chrome). Specifically, the .zip file downloads as expected.
When the app is deployed to shinyapps.io however, the file does not download (also using Chrome). A blank .html file appears with "Failed - Server problem" :
I can reproduce this with a minimal example that works in RStudio, but does not work deployed on shinyapps.io
library(shiny)
library(ggplot2)
library(zip)
zip_content <- function(file, plot1, plot2) {
path_plot1 <- file.path(tempdir(), "plot1.svg")
path_plot2 <- file.path(tempdir(), "plot2.svg")
ggsave(path_plot1, plot1)
ggsave(path_plot2, plot2)
zip(
zipfile = file, files = c(path_plot1, path_plot2), root = tempdir(),
mode = "cherry-pick"
)
}
ui <- fluidPage(downloadButton("downloadPlot"),
plotOutput("myplot1"),
plotOutput("myplot2"))
server <- function(input, output) {
first_reactive <- reactive({
p1 <- ggplot(mtcars, aes(x=mpg, y=wt))+geom_point(color="red",size=3)
p2 <- ggplot(mtcars, aes(x=mpg, y=wt))+geom_point(color="blue",size=3)
return(list(
p1=p1,
p2=p2
))
})
output$myplot1 <- renderPlot(first_reactive()$p1)
output$myplot2 <- renderPlot(first_reactive()$p2)
#Download both plots in a .zip file
output$downloadPlot <- downloadHandler(
filename="myplots.zip",
content = function(file){
zip_content(file, first_reactive()$p1, first_reactive()$p2)
},
contentType = "application/zip"
)
}
shinyApp(ui,server)
But when deployed to shinyapps.io it doesn't work