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:
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.
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:
as explained before, when you use {chromote}, shinyapps.io does not yet install Chrome. A temporary workaround is to force the use of the {pagedown} package which installs Chrome
when the application runs on shinyapps.io, you have to change the Chrome CLI arguments and use the --no-sandbox flag (because Chrome is running in a container) and the --disable-dev-shm-usage flag (because the shinyapps.io containers have low ressources)