msowers
msowers

Reputation: 1

When generating a RMarkdown PDF from Shiny, PDF saving and printing is disabled

I am trying to generate a report from a Shiny app where the user can select either HTML or PDF. I am able to generate a PDF from my .rmd file (LaTex format) and everything looks good with the layout/formatting. However, the PDF is opened (using Foxit PDF Reader) with a filename other than what I specified in my downloadhandler. I am also unable to save or print the PDF through the Foxit Reader window. The file name that is output is RStudio-randomletters.pdf (ex: RStudio-FoZvSx.pdf).

Generating an html report works fine with no issues, generates the correct file name that I specified, and opens a window for me to save or rename the file.

It seems that the PDF is the only issue so I'm not sure if it is just related to reading the PDF in the Foxit Reader or if it is something else?

Update

Using Adobe Acrobat instead of Foxit allows me to now save and print, but I am still having issues with the file name for the PDF.

Here is the code for my downloadhandler

output$downloadReport <- downloadHandler(

filename = function() {
  paste('Report', sep = '.', switch(
    input$format, PDF = 'pdf', HTML = 'html'))},

content = function(file) {
  out <- if (input$format == 'HTML'){rmarkdown::render('report.Rmd',
                                                       params = list(Name = input$Name,
                                                                     Reference = input$Reference),
                                                       switch(input$format,
                                                              PDF = pdf_document(), HTML = html_document()),
                                                       envir = new.env(parent = globalenv()))}
         else if (input$format == 'PDF'){rmarkdown::render('pdfreport2.Rmd',
                                                       params = list(Name = input$Name,
                                                                     Reference = input$Reference),
                                                       switch(input$format,
                                                              PDF = pdf_document(), HTML = html_document()),
                                                       envir = new.env(parent = globalenv()))}

  
  file.rename(out, file)})

Upvotes: 0

Views: 75

Answers (0)

Related Questions