Reputation: 113
My download button is showing an error when I use it to retrieve my report. The output id for the button is downloadData. What seems to be the error?
output$downloadData <- downloadHandler(
filename = function() {
paste('Final Report', '.csv', sep='')
},
content = function(file){
write.csv(csv_write,row.names=FALSE, na="")
})
Upvotes: 1
Views: 2570
Reputation: 3760
Here is the code that should work for You assuming that csv_write is the dataset which You wanna download:
output$downloadData <- downloadHandler(
"Final_Report.csv", content = function(file) {
write.csv(csv_write, file, row.names=FALSE, na="")
}
)
and first of all what kind of Error do You get?
Upvotes: 0
Reputation: 25375
See the documentation:
content = function(file) {
write.csv(data, file)
}
So you also have to pass the file parameter to the write.csv function. Assuming the data you want to write is called csv_write
, you should do:
write.csv(csv_write, file, row.names=FALSE, na="")
Working example
library(shiny)
csv_write = data.frame(a=c(1,2,3),b=c(1,2,3))
server <- shinyServer(function(input, output, session) {
output$downloadData <- downloadHandler(
filename = function() {
paste('Final Report', '.csv', sep='')
},
content = function(file){
write.csv(csv_write,file,row.names=FALSE, na="")
})
})
ui <-shinyUI(fluidPage(
downloadButton('downloadData', 'Download data')
))
shinyApp(ui,server)
Note that is csv_write is a reactive or reactiveValue, you should call csv_write() instead of csv_write.
Upvotes: 1