首页 文章

如何将视频文件上传到使用RStudio中的闪亮包创建的网站

提问于
浏览
0

我正在学习如何使用Rstudio中的Shiny包在网上上传视频 . 以下是我的ui.R代码

library(shiny)
shinyUI(fluidPage(
headerPanel("Shiny App Example with Video and Image"),

 sidebarLayout(
 sidebarPanel(
  fileInput("file","Upload the file", multiple = T), 
  h6("Default max. file size is 5MB"),
  hr(),
  h5("Select the read.table parameters below"),
  checkboxInput(inputId = 'header', label = 'Header', value = FALSE),
  checkboxInput(inputId = "stringAsFactors", "stringAsFactors", FALSE),
  br(),
  radioButtons(inputId = 'sep', label = 'Separator', choices =     c(Comma=',',Semicolon=';',Tab='\t', Space=''), selected = ','),
  h6(" Powered by:"),
  tags$img(src='RStudio-Ball.png', height=50, width=50)

  ),

mainPanel(
  uiOutput("tb")
  )

)
))

下一个代码是我的server.R

library(shiny)

shinyServer(function(input,output){

data <- reactive({
file1 <- input$file
if(is.null(file1)){return()} 
read.table(file=file1$datapath, sep=input$sep, header = input$header, stringsAsFactors = input$stringAsFactors)

})

output$filedf <- renderTable({
if(is.null(data())){return ()}
input$file

})

output$sum <- renderTable({
if(is.null(data())){return ()}
summary(data())

 })

output$table <- renderTable({
if(is.null(data())){return ()}
data()
})

output$tb <- renderUI({
if(is.null(data()))
  h6("intro video", br(), tags$video(src='reactive.mp4', type="video/mp4", width="350px", height="350px", controls="controls"))
else
  tabsetPanel(tabPanel("About file", tableOutput("filedf")),tabPanel("Data", tableOutput("table")),tabPanel("Summary", tableOutput("sum")))
 })
})

我可以启动该网站 . 从那里使用“上传”按钮,我可以导航到我的“reactive.mp4”文件所在的文件夹 . 但它在主面板中提供以下错误消息:“文件的空白开头”

在Rstudio控制台中,错误如下:

Error in read.table(file = file1$datapath, sep = input$sep, header = input$header,  : 
empty beginning of file
Warning in run(timeoutMs) : line 1 appears to contain embedded nulls
Warning in run(timeoutMs) :
incomplete final line found by readTableHeader on 'C:\Users\Lab-   User\AppData\Local\Temp\RtmpMxaMe9/8fe8ab38479dea3acaf755a8/0'

我也尝试更改视频文件的编码 . 不幸的是,它不播放视频 .

解:

我没有尝试过下面那个人给出的解决方案 . 因为我不想在Youtube上上传视频,然后在网络上托管它 .

因此,用户单击Rstudio控制台上的“启动应用程序”按钮 . 它会提示用户访问本地网站 . 当我使用浏览器打开网站时(按钮名称为“在浏览器中打开”,这可以在左侧角落找到) . 它会使用浏览器自动显示网站 . 有时在Windows中从本地Rstudio运行时以及在浏览器中运行时的行为是不同的 .

1 回答

  • 0

    要回到我的'quick'修复解决方案是使用 iframe ,您可以将视频上传到youtube然后使用iframe来显示它,如下所示:

    rm(list = ls())
    library(shiny)
    
    ui <- pageWithSidebar(
      headerPanel("Welcome!"),
      sidebarPanel(),
      mainPanel( HTML('<iframe width="600" height="400" src="//www.youtube.com/embed/dQw4w9WgXcQ" frameborder="0" allowfullscreen></iframe>')
      )
    )
    server <- function(input, output,session) {}
    shinyApp(ui = ui, server = server)
    

相关问题