How to copy screenshot to png from a html_widget

169 views Asked by At

Follow-up question to this R Shiny: Vtree plot not rendering with Shiny

With this code I generate a vtree htmlwidget. I would like to take a screenshot and save it in png. For this I use shinyscreenshot. But I only get a screenshot of all the rest but not the html_widget:

library(shiny)
library(vtree)
library(shinyscreenshot)


# Define UI ----
ui <- pageWithSidebar(
  
  # App title ----
  headerPanel("Cyl vtree"),
  
  # Sidebar panel for inputs ----
  sidebarPanel(
    screenshotButton(selector = "body")
  ),
  
  # Main panel for displaying outputs ----
  mainPanel(
    vtreeOutput("VTREE",  height = "800px")
  )
)

# Define server logic to plot ----
server <- function(input, output) {
  output[["VTREE"]] <- renderVtree({
    vtree(mtcars, "cyl")
  })
}

shinyApp(ui, server)

I used firefox and edge browser.

enter image description here

1

There are 1 answers

0
bretauv On BEST ANSWER

This is maybe due to shinyscreenshot limitations. Using another package (capture) works:

library(shiny)
library(vtree)


# Define UI ----
ui <- pageWithSidebar(
  
  # App title ----
  headerPanel("Cyl vtree"),
  
  # Sidebar panel for inputs ----
  sidebarPanel(
    capture::capture(
      selector = "body",
      filename = "all-page.png",
      icon("camera"), "Take screenshot of all page"
    )
  ),
  
  # Main panel for displaying outputs ----
  mainPanel(
    vtreeOutput("VTREE",  height = "800px")
  )
)

# Define server logic to plot ----
server <- function(input, output) {
  output[["VTREE"]] <- renderVtree({
    vtree(mtcars, "cyl")
  })
}

shinyApp(ui, server)

This is the output:

enter image description here