rshiny downloadHandler and ggsave unable to paste name in pdf output

Hello R and Rshiny Community -

I have this module for downloading images in my R shiny app, which works with one caveat. So if user selects png or tiff download option, then the pasted file name is as expected and it pops up as I would expect in the save file box.However when a user selects pdf, there is a delay, no save as box pops up, and it is automatically rendered in a pdf viewer. Additionally, the pasted name does not work and random letters are placed in front of the pdf (e.g. Rstudio-YXfJIJ.pdf rather than data-10.29.2020.pdf). Additionally, this problem does not happen on a linux or mac but this issue only occurs on windows.

Any thoughts on why

mod_downloadImage_ui <- function(id) {
  ns <- NS(id)
selectInput(ns("file_type"), label =  "File Type",
                        choices = c("pdf", "png", "tiff")),
downloadButton(ns("downloadPlot"),"Download Plot"))

mod_downloadImage_server <- function(input, output, session, tree_out) {
  ns <- session$ns
  output$downloadPlot <- downloadHandler(
    filename = function(){
      paste("data-",  Sys.Date(), ".", input$file_type,  sep="")},
    content = function(file){
      ggplot2::ggsave(file, plot=tree_out(),  
                     device = input$file_type)

When I do this on Windows, it does download the file with the correct name as PDF. It might be browser dependent - maybe your browser is set to automatically show instead of download PDFs? Just a guess

1 Like

Thank you for checking on a different windows machine :grin: Your suggestion got me thinking and when I changed my default browser to Chrome instead of Internet Explorer, everything downloaded as expected! :white_check_mark:

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.