'How Can I Set a Youtube Video to Autoplay Using R Shiny?
I'm using this code which will accept a Youtube URL and play the video in the RStudio viewer pane, rather than in a popout browser. It does exactly what I need it to do except that I would like it to autoplay when the function has run. I've seen a few other examples ( Like here and here ) where folks insert an allow = autoplay or something similar in the UI's fluidPage command but I haven't gotten it to work for me. I have additionally tried adding ?autoplay=1 to the URL, as described here, which works generally in any browser but seems to be ignored by R. Here's an example to replicate with:
videoplay <- function(url = "https://www.youtube.com/embed/wpHQnCaAJv8")
{
library(shiny)
xy <- c(784,479)
url <- gsub("watch\\?v=","embed/",url)
ui <- fluidPage(
HTML(paste0('<iframe width="',xy[1],'" height="',xy[2], '" src="', url,"?autoplay=1",'" frameborder="0"></iframe>'))
)
server <- function(input, output, session) {
}
runGadget(shinyApp(ui, server,options=c("launch.browser"=FALSE,"port"=1111)),port=1111,viewer = paneViewer())
}
Does anyone know how to make this video autoplay when the function is run? Appreciate any help!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
