Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download several png plots within one download button in shiny

Tags:

r

download

shiny

I am very new to shiny. I have several ggplot graghs. I added download button for each of them.
Here is an sample code:

output$salary_graph <- renderPlot({
print(salary_plot())
})
output$salary_plot_dl <- downloadHandler(
  filename = function() {
    "salary_plot.png"
},
content = function(file) {
png(file)
print(salary_plot())
dev.off()
}
)

I also have year_plot, group_plot and age_plot.

Currently, I would like to add a button which can downloads all my png plots. It can be a zip file which contains 4 png files or pdf file with 4 pages or four separate png files.

My questions here is not about creating a pdf or zip file to export all my plots in regular R script. I am asking the downloadHandler in the SHINY application. It is a unique question on this website.

Can someone teach me how to do it?

like image 568
cutebunny Avatar asked Aug 31 '15 21:08

cutebunny


1 Answers

You could make a pdf file with four pages in this way.

output$salary_graph <- renderPlot({
print(salary_plot())
})
output$salary_plot_dl <- downloadHandler(
  filename = function() {
    "Rplots.pdf"
},
content = function(file) {
pdf(file)
 print( salary_plot() )
 print( year_plot() )
 print( group_plot() )  
 print( age_plot() )
dev.off()
}
)
like image 143
Michal Majka Avatar answered Oct 04 '22 21:10

Michal Majka