screenshotButton {shinyscreenshot} | R Documentation |
Button that captures a screenshot of a shiny app
Description
Create a button that, when clicked, captures a screenshot of the Shiny app.
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 UI portion of a Shiny app, unlike
screenshot()
which is similar but gets called from the server.
Usage
screenshotButton(
selector = "body",
filename = "shinyscreenshot",
id = "",
scale = 1,
timer = 0,
download = TRUE,
server_dir = NULL,
ns = shiny::NS(NULL),
...
)
Arguments
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. |
ns |
The |
... |
Any other parameters that should be passed along to the |
Saving to the server
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.
See Also
Examples
if (interactive()) {
library(shiny)
library(shinyscreenshot)
shinyApp(
ui = fluidPage(
h1("{shinyscreenshot} demo"),
screenshotButton(label = "Capture entire page"),
screenshotButton(label = "Capture plot", id = "plot"), br(), br(),
numericInput("num", "Number of points", 50),
plotOutput("plot")
),
server = function(input, output) {
output$plot <- renderPlot({
plot(runif(input$num))
})
}
)
}