How do I take a screenshot of a specific plotly chart in a shiny app and not the whole UI?
library(shiny)
library(shinyscreenshot)
library(plotly)
ui <- fluidPage(
plotlyOutput("plot"),
actionButton("go", "Take a screenshot")
)
server <- function(input, output) {
output$plot<-renderPlotly({
fig <- plot_ly(
x = c("giraffes", "orangutans", "monkeys"),
y = c(20, 14, NA),
name = "SF Zoo",
type = "bar"
)
fig
})
observeEvent(input$go, {
screenshot()
})
}
shinyApp(ui, server)
You could use the selector
argument:
By default, the entire page is captured. If you'd like to capture a specific part of the screen, you can use the selector parameter to specify a CSS selector. For example, if you have a plot with ID myplot then you can use screenshot(selector="#myplot")
In this case :
screenshot(selector="#plot")