Download multiple graphs within the press on single button

715 views
Skip to first unread message

Timothy Tuti

unread,
Jun 26, 2013, 5:06:39 AM6/26/13
to shiny-...@googlegroups.com
In my ui.R, I have code that is for plotting multiple graphs for each tab selected which looks like this:

tabPanel(id="danger","Danger Signs",
               div(class="span6",plotOutput("dgrCyanosis",width="380px")), #the div helps put plots side by side
               div(class="span6",plotOutput("dgrGrunting",width="380px")),
               div(class="span6",plotOutput("dgrAvpu",width="380px")),
               div(class="span6",plotOutput("dgrAcidotic",width="380px")),
               HTML('<br clear="all" />'),
               downloadButton('histPng','PNG'),
               downloadButton('histPdf','PDF')
               ),#end of danger signs tab

I would like to be able to download all this graphs when I press one of the buttons. How would my code in the server.R look like?

Best regards,
Timothy Tuti

Mike C

unread,
Jun 26, 2013, 3:11:45 PM6/26/13
to shiny-...@googlegroups.com
The best solution that I came up with was zipping the files together and downloading the zipped folder-
(my code simplified)

output$aDL <- downloadHandler(
    filename <- function() {
     paste("Analysis Tables",atime(), '.tar', sep='')}, #name the .tar file
    content <- function(file) {
if(!file.exists(paste("
Analysis",atime()))){ #check if the directory has been made yet, I use the time/date at which the action button was pressed to make it relatively unique
dir.create(paste("Analysis",atime()))}#make the dir if not
in.path=getwd()
setwd(paste(in.path,"/A ",atime(),sep="")) #go into the dir, alternatively you could just set the path of the file each time

tmp=Abothx()
write.table(tmp,file=paste("both",atime()))

tmp=Aupx()
write.table(tmp,file=paste("up",atime()))


tmp=Adownx()
write.table(tmp,file=paste("down",atime()))

setwd(in.path) #go back up a level if needed
tar(file,paste("
Analysis",atime())) # tar it
})

Alex Brown

unread,
Jun 26, 2013, 11:33:06 PM6/26/13
to shiny-...@googlegroups.com
I would humbly suggest that OSX provides an option to print to PDF, and Chrome on any OS does too.

-Alex
Reply all
Reply to author
Forward
0 new messages