使用 actionButton() 在闪亮仪表板的模态对话框中播放视频

问题描述

我在下面有一个闪亮的仪表板,其中包含一个 actionButton()。当按下此按钮时,会出现一个带有另一个 actionButton() 的模式对话框。当我按下它时,我希望可以从 here 下载并保存在名为 www 的子目录中的视频在模态中显示和播放。我也对 youtube 视频开放,但它应该在按下按钮后显示

    library(shiny)
    library(shinydashboard)
    
    ui <- dashboardPage(
      dashboardHeader(titleWidth = 0
                      # Set height of dashboardHeader
                      ),dashboardSidebar(),dashboardBody(
        tags$div(style="display:inline-block",title="Using the range slider",actionButton("info","",icon = icon("info-circle"),style='padding:10px; font-size:80%')),)
    )
    
    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;')),tags$div(style="display:inline-block",actionButton("play",icon = icon("play"),#tags$video(id="video2",type = "mov",src = "Screen Recording 2021-05-25 at 4.03.51 AM.mov",controls = "controls")
#or youtube file
        HTML('<iframe width="200" height="100" src="//www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allowfullscreen></iframe>') )

          
        ))
        
      })
      
    }
    
    shinyApp(ui,server)

解决方法

试试这个:

showModal(modalDialog(
  title = span(h3(strong("Distribution of cumulative reported cases (logarithmic scale)"),style = 'font-size:16px;color:#6cbabf;')),tags$div(
    style = "display:inline-block",title = "Using the range slider",actionButton(
      "play","",icon = icon("play"),style = 'padding:10px; font-size:80%',onclick = "document.getElementById('video2').play()"
    )
  ),tags$video(
    id = "video2",type = "mov",src = "Screen Recording 2021-05-25 at 4.03.51 AM.mov",controls = ""
  )
      
))