Error after using pagedown to generate a pdf from html in a shinyapp

I have written an app that creates a downloadable report, I was hoping to use the pagedown package to create a pdf from a html which is better formatted and more presentable. It tested fine locally on my machine. After deployment, the document failed to download with the following error from the logs:

Warning: Error in find_chrome: Cannot find Chromium or Google Chrome
[No stack trace available]

I am using Google Chrome to view the app but I am guessing there's more to it than this?

The code to handle the download is as follows:

output$downloadDrug <- downloadHandler(
    filename = function() {("drug-instructions.pdf)},
    
    content = function(file) {
      src <- normalizePath('report_drugHTML.Rmd')
      src2 <- normalizePath("printout.css")
      label <- normalizePath("pxLabel.png")
      logo <-normalizePath("logo.png")
      fasting <- normalizePath("fasting.png")
      
      owd <- setwd(tempdir())
      on.exit(setwd(owd))
      file.copy(src, 'report_drugHTML.Rmd', overwrite = TRUE)
      file.copy(src2, "printout.css", overwrite = TRUE)
      file.copy(label, "pxLabel.png", overwrite = TRUE)
      file.copy(logo, "logo.png", overwrite = TRUE)
      file.copy(fasting, "fasting.png", overwrite = TRUE)
      
      library(rmarkdown)
      out <- render('report_drugHTML.Rmd', 
                    params = list(name = input$px_name, dob = input$dob),
                    'html_document')
      library(pagedown)
      out <- pagedown::chrome_print(out, "drug-instructions.pdf")
      file.rename(out, file)
    }
  )

Any suggestions would be greatly appreciated.

It seems that pagedown cannot find chrome or chromium on the server that runs the Shiny app.
First, check that Chrome or Chromium is installed on this server.
The Chrome or Chromium must also be available through the PATH environment variable.
Last thing: when using pagedown::chrome_print() in Shiny, you have to use async = TRUE.

You can see a recent convo with @smsenkier on this subject here https://github.com/rstudio/pagedown/issues/91#issuecomment-558331313

2 Likes

Thanks for taking the time to reply. I've only been coding for a few months, so forgive me if some things seem obvious to others. The server I've uploaded to is just the shinyapps server, would this cause problem with pagedown? Please can you explain what you mean by "through the PATH environment variable"?

My mistake, I haven't noticed that you uploaded your app on shinyapps.io.
In that case, someone has to send the installation script for the pagedown package dependencies to the shinyapps.io maintainers.
I did it, this is here: https://github.com/rstudio/shinyapps-package-dependencies/pull/220

Now, we have to wait for this pull request to be merged. It may take a few weeks.

I am sorry for the use of technical terms. An environment variable is a special variable that characterize the context of your R session. You can print the current environment variables with Sys.getenv(). The PATH is a special one that contains all the directories where programs can be found. This is essential to lookup for specific programs. But if you use shinyapps.io, you haven't to worry about these technical details. When the previously mentioned pull request will be merged, the pagedown::chrome_print() function should work.

2 Likes

Wonderful. So I only need to sit and wait then. Will there be some way of getting notified about this? I have only started learning R for a few months, initially for data analysis, and saw the potential use for an app in relation to my work. I am very grateful for any education there is to learn more about this.

1 Like

If you have a Github account, you can subscribe to the notifications on this page https://github.com/rstudio/shinyapps-package-dependencies/pull/220 (on the right hand side of the page, there is a "Subscribe" button).

1 Like