How do I take a screenshot with a shiny app at the click of a button?

I've included a minimal example to work. There is a button download

that, when clicked, should download a pdf screenshot of the shiny application. The code looks like this.

server <- function(input, output) {
  output$distPlot <- renderPlot({
    hist(rnorm(input$obs), col = 'darkgray', border = 'white')
  })

}

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      sliderInput("obs", "Number of observations:", min = 10, max = 500, value = 100),
      actionButton("btn", "Download")

    ),
    mainPanel(plotOutput("distPlot"))
  )
)

shinyApp(ui = ui, server = server)

      

Thanks in advance!

+3


source to share





All Articles