R Shiny: Download existing file
A few years later, but I think there is a simpler way if you do not need dynamic file generation by placing the file in the www/
folder of the Shiny app:
|
|- app.R
|- www/
- downloadme.csv
Then when your Shiny app is live the file is available at shiny-url.com/downloadme.csv
- or when testing locally 127.0.0.1:1221/downloadme.csv
e.g. to use within your Shiny ui:
# in ui somewhere
...
a(href="downloadme.csv", "Download CSV", download=NA, target="_blank")
...
After poking around with different file handling functions I discovered that file.copy
can be used to download the file.
I change downloadHandler
to:
output$downloadData <- downloadHandler(
filename <- function() {
paste("output", "zip", sep=".")
},
content <- function(file) {
file.copy("out.zip", file)
},
contentType = "application/zip"
)