Reputation: 423
I am having some trouble downloading .png graphs with Shiny using downloadHandler while I don't have difficulty with .pdf.
I would like to create some app in which the user download a data file and, in one of the many tabs, create some histograms; afterward the user can choose among different file formats to download the graphs (for instance .png and .pdf).
When I check the .pdf button the .pdf file pops up without a window asking to save the file; when the button .png is checked a windows pops up but the .png is not saved.
Here you can find the pieces of my code of interest:
# --------------------------------------------------------------------
server.r
output$down <- downloadHandler(
filename = function(){
paste("Histogram", input$downhist, sep =".")
},
content = function(file){
if(input$downhist == "pdf")
pdf(file)
else
png(file)
hist(data()$SF)
dev.off()
}
)
# -------------------------------------------------------------------------
ui.r
...
radioButtons(inputId = "downhist",
label = "4. Select the histogram file type",
choices = list("png", "pdf")),
...
For the rest my code works just fine.
I have read many posts about but I can't manage to find a solution. I can post more code if needed.
Thanks!
Upvotes: 1
Views: 624
Reputation: 423
It turned out that I should have used Run External
when running the app. I don't know the technical reasons but the code now works like a charm.
Upvotes: 3