How to properly configure Google Chrome on Shinyapps.io (because of webshot2)

I made a Shiny app, which allows users to download specific plots based on the data they upload. While the app works perfectly on my computer, it fails to download the plots once deployed on Shinyapps.io. One of the downloaded charts is created with flextable::save_as_image(), which makes use of {webshot2}. Based on my conversations with @cderv , this function is the culprit and he is right because when I remove that chart, everything works perfectly. The log message on Shinyapps.io is: 'google-chrome' and 'chromium-browser' were not found. Try setting the CHROMOTE_CHROME environment variable or adding one of these executables to your PATH.

As a {golem} user, I edited my golem-config.yml, which now looks like this:

default:
  golem_name: TechEvalsExtractor
  golem_version: 0.0.0.9000
  app_prod: no
production:
  app_prod: yes
  CHROMOTE_CHROME: /usr/bin/google-chrome
dev:
  golem_wd: F:/Projects/TechEvalsExtractor

But I am still have the same issue. So my question is: how do I configure Google Chrome on Shinyapps.io?
Thank you

1 Like

New vignette for pagedown also use Chrome and I had similar question as you do but without answers. This may help you: GitHub - RLesur/chrome_print_shiny: How to use pagedown::chrome_print() in a Shiny app?

Please report back on solution if you happen to find anything. Also, I'm also curious if Chromium would work instead of Chrome.

IMO, the very first problem is certainly related to system dependencies.
In shinyapps.io, system dependencies are managed through this repository: GitHub - rstudio/shinyapps-package-dependencies: Collection of bash scripts that install R package system dependencies
As you can see in the list of packages (shinyapps-package-dependencies/packages at master · rstudio/shinyapps-package-dependencies · GitHub), the system dependencies for {chromote} (ie Chrome) are not declared.
So, Chrome is not installed in your deployment.

3 Likes

Chromium cannot easily be installed in Shinyapps. This is because Shinyapps uses containers with a focal distro: until bionic, Chromium was available as a deb file. However since disco, Chromium is only distributed as a snap package but snapd does not work in containers.

1 Like

Here is a minimal shiny application which works on shinyapps.io

library(shiny)
library(webshot2)
# force the use of pagedown to install chrome on shinyapps.io (this is a workaround)
library(pagedown)
# force the use of curl because chromote needs it (see https://github.com/rstudio/chromote/issues/37)
library(curl)

ui <- fluidPage(
    downloadButton("downloadScreenshot", "Download screenshot")
)

server <- function(input, output) {
    message(curl::curl_version()) # check curl is installed
    if (identical(Sys.getenv("R_CONFIG_ACTIVE"), "shinyapps")) {
        chromote::set_default_chromote_object(
            chromote::Chromote$new(chromote::Chrome$new(
                args = c("--disable-gpu", 
                         "--no-sandbox", 
                         "--disable-dev-shm-usage", # required bc the target easily crashes
                         c("--force-color-profile", "srgb"))
            ))
        )
    }

    output$downloadScreenshot <- downloadHandler(
        filename = function() {
            paste("screenshot-", Sys.Date(), ".png", sep="")
        },
        content = function(file) {
            webshot2::webshot("https://github.com/rstudio/shiny", file)
        }
    )
}

shinyApp(ui = ui, server = server)

Some comments:

6 Likes

This topic was automatically closed 7 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.