问题描述
当我在 shiny
应用中点击播放视频时,有没有办法在第二个弹出模态中播放模态内显示的 YouTube 视频?
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)
解决方法
试试这个
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)
,
我无法点击视频,但也许这样的操作可行?
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)