闪亮| iframe |反应

时间:2015-03-11 09:27:02

标签: r shiny

我正在尝试显示动态iframe,以根据用户对网址的输入显示YouTube视频。
我的代码没有生成错误,但视频没有显示,你有什么解决方案吗? 非常感谢提前!
问候,
托马斯

我的代码:

ui.R

box(title = "settings", status = "warning", solidHeader = TRUE, width = 2, textInput("texturli", label = "enter valid Youtube URL", value = "https://www.youtube.com/watch?v=C7mXGMcpA0g"),
                    actionButton("geturl", label = "launch analysis")
                  ),
box(title = "video", status = "primary", solidHeader = TRUE, width = 3, 
tags$iframe(src = "https://www.youtube.com/watch?v=C7mXGMcpA0g"), # this works fine
htmlOutput("test")) # this does not work

server.R

url <- reactive({
    input$geturl
    isolate(paste0(input$texturli))
  })

  output$test <- renderUI({
    tags$iframe(src = url())
  })

2 个答案:

答案 0 :(得分:0)

当我运行代码时,我在浏览器的控制台中收到此错误:

Refused to display 'https://www.youtube.com/watch?v=C7mXGMcpA0g' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'

请尝试使用Youtube嵌入式链接修复此错误,而不是使用视频链接(请参阅thisthis):

http://www.youtube.com/embed/C7mXGMcpA0g

在动态iframe中,您可以执行以下操作:

url <- reactive({
    input$geturl
    isolate(paste0("http://www.youtube.com/embed/",sub(".*v=(.*)","\\1",input$texturli)))
  })

答案 1 :(得分:0)

我找到了解决方案:

ui.R

box(title = "settings", status = "warning", solidHeader = TRUE, width = 2,  
    textInput("texturli", label = "enter valid Youtube URL", value = https://www.youtube.com/watch?v=C7mXGMcpA0g"),
    actionButton("geturl", label = "launch analysis")),  

box(title = "video", status = "primary", solidHeader = TRUE, width = 3, 
htmlOutput("test"))

server.R

url <- reactive({
input$geturl
isolate(paste0("https://www.youtube.com/embed/",sub(".*v=(.*)","\\1",input$texturli)))})

output$yvideo <- renderUI({
tags$iframe(id = "app", src = url(), width = "100%")})

此致

托马斯