如何在 Shiny 中显示通过 fileInput 上传的视频?

How do I display a video that I've uploaded via fileInput in Shiny?

所以我尝试使用 Shiny 中的 fileInput 小部件上传视频,然后让该视频显示在主面板中。我是 R 的新手,并使用了多种示例来尝试找到解决方案,因此如果有任何代码错误,那就是原因。在此先感谢您的帮助!

我的ui脚本:

library(shiny)

shinyUI(fluidPage(
  headerPanel(title = 'Shiny Example'),
  sidebarLayout(
    sidebarPanel(
      fileInput("file", "Choose Video File", accept = ".mp4"),
      uiOutput("selectfile")
    ),
    mainPanel(
      uiOutput('video')
    )
    
  )
)
)

我的服务器脚本:

library(shiny)
shinyServer(function(input, output) {})

适用于 Firefox:

library(shiny)
options(shiny.maxRequestSize = 30*1024^2)

ui <- fluidPage(
  headerPanel(title = 'Shiny Example'),
  sidebarLayout(
    sidebarPanel(
      fileInput("file", "Choose Video File", accept = ".mp4")
    ),
    mainPanel(
      uiOutput('video')
    )
  )
)

server <- function(input, output){
  Video <- eventReactive(input[["file"]], {
    input[["file"]][["datapath"]]
  })
  output[["video"]] <- renderUI({
    req(Video())
    file.rename(Video(), "www/myvideo.mp4")
    tags$video(
      width="320", height="240", controls="",
      tags$source(src="myvideo.mp4", type="video/mp4")
    )
  })
}

shinyApp(ui, server)

您必须有一个 www 子文件夹。