appshot performs a webshot using two different methods depending upon the object provided. If a 'character' is provided (pointing to an app.R file or app directory) an isolated background R process is launched to run the Shiny application. The current R process then captures the webshot. When a Shiny application object is supplied to appshot, it is reversed: the Shiny application runs in the current R process and an isolated background R process is launched to capture a webshot. The reason it is reversed in the second case has to do with scoping: although it would be preferable to run the Shiny application in a background process and call webshot from the current process, with Shiny application objects, there are potential scoping errors when run this way.

appshot(
  app,
  file = "webshot.png",
  ...,
  port = getOption("shiny.port"),
  envvars = NULL
)

# S3 method for character
appshot(
  app,
  file = "webshot.png",
  ...,
  port = getOption("shiny.port"),
  envvars = NULL
)

# S3 method for shiny.appobj
appshot(
  app,
  file = "webshot.png",
  ...,
  port = getOption("shiny.port"),
  envvars = NULL,
  webshot_timeout = 60
)

Arguments

app

A Shiny app object, or a string naming an app directory.

file

A vector of names of output files. Should end with an image file type (.png, .jpg, .jpeg, or .webp) or .pdf. If several screenshots have to be taken and only one filename is provided, then the function appends the index number of the screenshot to the file name. For PDF output, it is just like printing the page to PDF in a browser; selector, cliprect, expand, and zoom will not be used for PDFs.

...

Other arguments to pass on to webshot.

port

Port that Shiny will listen on.

envvars

A named character vector or named list of environment variables and values to set for the Shiny app's R process. These will be unset after the process exits. This can be used to pass configuration information to a Shiny app.

webshot_timeout

The maximum number of seconds the phantom application is allowed to run before killing the process. If a delay argument is supplied (in ...), the delay value is added to the timeout value.

Value

Invisibly returns the normalized path to all screenshots taken. The character vector will have a class of `"webshot"`.

Examples

if (interactive()) {
  appdir <- system.file("examples", "01_hello", package="shiny")

  # With a Shiny directory
  appshot(appdir, "01_hello.png")

  # With a Shiny App object
  shinyapp <- shiny::shinyAppDir(appdir)
  appshot(shinyapp, "01_hello_app.png")
}