闪亮 |框架 |被动的

Shiny | iframe | reactive

我正在尝试根据 URL.
的用户输入显示动态 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())
  })

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

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

不要将 link 用于视频,而是尝试使用 Youtube 嵌入 link 来修复此错误(参见 this and this):

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

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

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

我找到了解决方案:

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%")})

此致,

托马斯