6

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?

cutebunny
  • 769
  • 2
  • 9
  • 21
  • 2
    possible duplicate of [How to print R graphics to multiple pages of a PDF and multiple PDFs?](http://stackoverflow.com/questions/1395410/how-to-print-r-graphics-to-multiple-pages-of-a-pdf-and-multiple-pdfs) – zero323 Aug 31 '15 at 21:38
  • @zero323 this one is not in the shiny. It is not a duplicate. – cutebunny Aug 31 '15 at 21:51

1 Answers1

4

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()
}
)
Michal Majka
  • 5,332
  • 2
  • 29
  • 40