Error when using pagedown::chrome_print() in shinyapps.io

I have a problem that is exactly like this

but the solution mentioned in that post does not work for me.

It is a markdown document that usually takes a minute or two to run on my PC.
It runs on Shinyapps and generates a html that fails to download.
The log says
Warning: Error in is_remote_protocol_ok: Cannot find headless Chrome after 20 attempts

This is my Server side code.

     output$report <- downloadHandler(
  # For PDF output, change this to "report.pdf"
  filename = "report.pdf",
  content = function(file) {
    # Copy the report file to a temporary directory before processing it, in
    # case we don't have write permissions to the current working dir (which
    # can happen when deployed).
 
    tempReport <- file.path(here("temp"), "report_2021.Rmd")
    file.copy("report_2021.Rmd", tempReport, overwrite = TRUE)
    
    # Set up parameters to pass to Rmd document
    params <- list(Team = input$1, Level = input$Level, Year = input$Year, 
                   Competition = input$4, Game = input$5)
    
    # Knit the document, passing in the `params` list, and eval it in a
    # child of the global environment (this isolates the code in the document
    # from the code in this app).
    library(rmarkdown)
    out <- pagedown::chrome_print( render(tempReport,  params = params,
                  envir = new.env(parent = globalenv())),
      extra_args = c("--disable-gpu",
                     "--no-sandbox"), 
      wait = 15,
      timeout = 300,
                            async = T,
                             verbose = TRUE
                             )
    file.rename(out, file)
    
    shiny::withProgress(
      message = paste0("Downloading Report"),
      value = 0,
      {
        shiny::incProgress(1/10)
        Sys.sleep(1)
        shiny::incProgress(5/10)
        }
    )
    
    
  }
)

Hi @Barry_Cleary,

I'm not familiar with shinyapps however I wonder whether the container is a focal one or a xenial one.

The reason is the following: on focal, Chromium is now installed with snap and snap does not work well with containers.

If shinyapps now launches focal containers, one has to update the Chromium install command here shinyapps-package-dependencies/install at master · rstudio/shinyapps-package-dependencies · GitHub to bypass the snap install.

I did a dummy Shiny app on shinyapps.io that shows the result of lsb_release -c, see here: OS

shinyapps.io containers are now built on top of focal, so I can confirm you that this is the problem: chromium was installed with snap. I will open an issue.

Here is the issue [pagedown] Chromium installation trouble with Ubuntu 20.04 · Issue #290 · rstudio/shinyapps-package-dependencies · GitHub

edit: I've opened a pull request to fix this issue (see [pagedown] use Google Chrome instead of Chromium by RLesur · Pull Request #291 · rstudio/shinyapps-package-dependencies · GitHub).

Hi ! I added the extra_args and it worked. However, the next time I tried to upload an app that rendered Rmd I had the same problem. Thanks for opening the request @rlesur !

I have tried to run this app after the merged request above by @rlesur and I'm still getting the error.

image|690x178

It is failing after it renders the html.

Here is my current download code

    output$report <- downloadHandler(
  # For PDF output, change this to "report.pdf"
  filename = "report.pdf",
  content = function(file) {
       
    tempReport <- file.path(here("temp"), "GIFootball_2021.Rmd")
    file.copy("GIFootball_2021.Rmd", tempReport, overwrite = TRUE)
    
    # Set up parameters to pass to Rmd document
    params <- list(Team = input$Team, Level = input$Level, Year = input$Year, 
                   Competition = input$Comp, Game = input$Game)

        html_fn <- rmarkdown::render(tempReport,  params = params,
                                 envir = new.env(parent = globalenv()))
    
    pagedown::chrome_print(html_fn, file,
                           extra_args = c("--disable-gpu", "--no-sandbox"), 
                              async = TRUE)
    

    
  }
)

}

I have written a demo app here: GitHub - RLesur/chrome_print_shiny: How to use pagedown::chrome_print() in a Shiny app?

I have also tried to deploy it on shinyapps and I have noticed that the new image is not yet deployed to shinyapps.io.

IMO, we have to wait for the new version to be deployed.

1 Like

Thank you so much @rlesur!

Do you have an idea how how long they'll take to deploy the new image?

Sorry, I have no idea. Maybe someone working in the shinyapps team could tell us.

Hi, the new image is now deployed: pagedown::chrome_print() now works on shinyapps.io.
Please, do not hesitate to inspect my above mentioned project for further details on using pagedown::chrome_print() with this service.

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.