Taking screenshot in Shiny App in R not working

254 views Asked by At

I am trying to take a screenshot of my shiny app.

Everything is fine when I have just plots. But when I add a video, it just not working. I have the plots ok, but video area its just empty.

This is my code:

library(shiny)
library(tidyverse)
library(shinyscreenshot)

ui <- fluidPage(
  actionButton("go","Go"),
div(
  plotOutput("plot1"),
  tags$iframe(id = "video",width="560", height="315", src="https://www.youtube.com/embed/T1-k7VYwsHg", frameborder="0", allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture",
              allowfullscreen=NA),
  plotOutput("plot2")
)


)

server <- function(input, output, session) {

  output$plot1 <- renderPlot({

    ggplot(mtcars, aes(mpg,cyl)) + geom_point()

  })
  output$plot2 <- renderPlot({

    ggplot(mtcars, aes(mpg,cyl)) + geom_point()

  })

observeEvent(input$go, {
  shinyscreenshot::screenshot(id = "video")
  })
}

shinyApp(ui, server)

Any help?

Is because the iframe?

How can I solve this??

Many thanks

1

There are 1 answers

0
ismirsehregal On

shinyscreenshot is based on the html2canvas JavaScript library.

One of html2canvas limitations is mentioned here:

All the images that the script uses need to reside under the same origin for it to be able to read them without the assistance of a proxy.

This restriction applies to the iframe unless you are willing to set up a proxy server.

However, videos in general seem to be an issue.

You could try to screenshot another hidden html tag instead as suggested here.