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
- related to curl package is required for chromote to work · Issue #37 · rstudio/chromote · GitHub, you also have to force the use of {curl}
- 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)