【问题标题】:Play youtube video that is displayed in a modal in an another pop up modal when pressed in a shiny app在闪亮的应用程序中按下时,播放在另一个弹出模式中以模式显示的 youtube 视频
【发布时间】:2021-08-17 10:58:45
【问题描述】:

当我点击在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)    

【问题讨论】:

    标签: javascript r video shiny modal-dialog


    【解决方案1】:

    试试这个

    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)
    

    【讨论】:

      【解决方案2】:

      我无法点击视频,但也许这样的方法会起作用?

      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)
      

      【讨论】:

      • 我喜欢它,但关键是模式要更大,以便视频更大且可观看
      • 我想我应该改变视频的大小
      • 您可以在modalDialog 中使用size = 'l' 并在iframe 中增加高度和宽度。
      • 我根据您的回答编辑了我的 Q,以更好地满足我的需求
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-01
      • 2012-06-21
      • 2017-08-08
      • 2021-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多