I've got my download function to do everything right, when the save as screen comes up, the file name I specified appears. When I click on save the window closes, but no file gets saved...
The same plot works fine in the app, the only problem is I cant seem to save it to a PNG file.
I run the shine app on my laptop and use RStudio.
Here is some extracts of my code.
ui.R
downloadButton('downloadSMemPlot', 'Download Graph')
server.R
'#draw membersip plot
s.MemPlotInput <- reactive({
'#some code to get data
s.MemPlot <- ggplot() +
geom_density(aes(x=Age, fill = Years), data=s.ben, alpha = 0.5) +
ggtitle("Density of beneficiary ages") +
theme_igray() +
theme(plot.title = element_text(lineheight=.8, face="bold")) +
xlab("Age in full years") + ylab("Density")+
scale_fill_hue()
})
output$s.memplot <- renderPlot({
print(s.MemPlotInput())
})
'#download membership plot
output$downloadSMemPlot <- downloadHandler(
filename = "MembershipPlot.png",
content = function(file) {
png(file, type='cairo')
print(s.MemPlotInput())
dev.off()
},
contentType = 'application/png'
)
You want
not
Although I don't think that's the problem. Are you running it within RStudio's preview pane or in an external browser? I had the same problem with downloading when using the preview pane but it worked fine on my browser.