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

Time:10-20

So im trying to use the fileInput widget in Shiny to upload a video and then have that video be displayed in the mainPanel. Im new to R and have used a mixture of examples to try to find a solution so if there's any code errors then that'll be why. Thanks in advance for any help!

My ui script:

library(shiny)

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

My server script:

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

CodePudding user response:

Works with 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)

You must have a www subfolder.

  • Related