screenshot | R Documentation |
Screenshots can be either of the entire viewable page (default), or of a specific
section of the page. The captured image is automatically downloaded as a
PNG image.
This function gets called from the server portion of a Shiny app, unlike
screenshotButton()
which is similar but gets called from the UI.
screenshot(
selector = "body",
filename = "shinyscreenshot",
id = "",
scale = 1,
timer = 0,
download = TRUE,
server_dir = NULL
)
selector |
CSS selector for the element that should be captured. If multiple elements match the selector, only the first one is captured. Default is to capture the entire page. |
filename |
Name of the file to be saved. A PNG extension will automatically be added. |
id |
As an alternative to |
scale |
The scale of the image. Default is 1, which means the dimensions of the image will be exactly the dimensions in the browser. For example, a value of 2 will result in an image that's twice the height and width (and a larger file size). |
timer |
Number of seconds to wait before taking the screenshot. Default is 0, which takes a screenshot immediately. |
download |
If |
server_dir |
Directory on the server where the screenshot image should be saved. See 'Saving to the server' section below. |
By default, the image is downloaded to the user's computer and is not stored on the server
running the Shiny app. If a server_dir
is provided, then the image is stored to this
directory on the server. Note that only the directory should be specified, not the file name.
If saving the image is successful, input$shinyscreenshot
will contain the full path to
the image. If not, input$shinyscreenshot
will contain an empty string (""
).
The directory must exist and be writeable. If NULL
, the image is not saved to the server.
If a relative path is provided, it is relative to the Shiny app's working directory. For
example, server_dir="."
will save the image in the same directory that the Shiny app is in.
screenshotButton()
if (interactive()) {
library(shiny)
library(shinyscreenshot)
shinyApp(
ui = fluidPage(
h1("{shinyscreenshot} demo"),
numericInput("num", "Number of points", 50),
plotOutput("plot"),
actionButton("screenshot1", "Capture entire page"),
actionButton("screenshot2", "Capture plot")
),
server = function(input, output) {
observeEvent(input$screenshot1, {
screenshot()
})
observeEvent(input$screenshot2, {
screenshot(id = "plot")
})
output$plot <- renderPlot({
plot(runif(input$num))
})
}
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.