Play youtube video that is displayed in a modal in an another pop up modal when pressed in a shiny app

Viewed 191

Is there a way to play the youtube video that is displayed inside a modal in a second pop up modal when I click to play the video in a shiny app?

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(disable = T),
  dashboardBody(
    actionButton('info', 'Information')
  )
)

server <- function(input, output) {
  observeEvent(input$info,{
    showModal(modalDialog(
      title = span(h3(strong("Distribution of cumulative reported cases (logarithmic scale)"), style = 'font-size:16px;color:#6cbabf;')),
      
      fluidRow(
        actionButton('hit', 'Open video in popup'),
        observeEvent(input$hit,{
          showModal(modalDialog(
            title = "Video",
            HTML(paste0('<iframe width="860" height="500" src="https://www.youtube.com/embed/' ,"aQlTAznANDQ",'" frameborder="0" allowfullscreen></iframe>')),
            size = 'l'
          ))
        })
      )

    ))
    
  })
}

shinyApp(ui, server)    
2 Answers

Try this

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    actionButton("show", "Show Video") 

  )
)

server <- function(input, output) {
  observeEvent(input$show, {
    showModal(modalDialog(title = "my video",
                          HTML('<iframe width="560" height="315" src="https://www.youtube.com/embed/aQlTAznANDQ" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>')
                          
                          )
              )
  })
}

shinyApp(ui, server)

output

I couldn't get the click on the video but perhaps something like this would work?

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(disable = T),
  dashboardBody(
    actionButton('hit', 'Open video in popup')
  )
)

server <- function(input, output) {
  observeEvent(input$hit,{
               showModal(modalDialog(
                 title = "Video",
                 HTML(paste0('<iframe width="860" height="500" src="https://www.youtube.com/embed/' ,"aQlTAznANDQ",'" frameborder="0" allowfullscreen></iframe>')),
                 size = 'l'
               ))
  })
}

shinyApp(ui, server)
Related