【问题标题】:opening webpages within shiny window without opening a separate window在闪亮的窗口中打开网页而不打开单独的窗口
【发布时间】:2014-11-06 06:00:24
【问题描述】:

我有一个 URL,它会随着闪亮应用的输入而改变。我想打开一个网页并在闪亮窗口的标签面板中显示它。每次我更改输入时,网页 URL 都会更新,我想在同一个选项卡中显示该页面。到目前为止,网页在一个单独的窗口中打开,而不是使用 R 的 browseURL 功能的闪亮窗口。

这是我的案例的小测试示例

ui.R

shinyUI(fluidPage(
  titlePanel("opening web pages"),
  sidebarPanel(
    selectInput(inputId='test',label=1,choices=1:5)
    ),
  mainPanel(
    htmlOutput("inc")
  )
))

服务器.R

shinyServer(function(input, output) {
  getPage<-function() {
    return((browseURL('http://www.google.com')))
  }
  output$inc<-renderUI({
    x <- input$test  
    getPage()
    })
})

【问题讨论】:

  • 请提供一个可重现的最小示例。
  • 我已经包含了一个相同的代码 sn-p。

标签: r shiny


【解决方案1】:

不要使用browseURL。这会在新窗口中明确打开网页。

library(shiny)
runApp(list(ui= fluidPage(
  titlePanel("opening web pages"),
  sidebarPanel(
    selectInput(inputId='test',label=1,choices=1:5)
  ),
  mainPanel(
    htmlOutput("inc")
  )
),
server = function(input, output) {
  getPage<-function() {
    return((HTML(readLines('http://www.google.com'))))
  }
  output$inc<-renderUI({
    x <- input$test  
    getPage()
  })
})
)

如果你想镜像页面,你可以使用iframe

library(shiny)
runApp(list(ui= fluidPage(
  titlePanel("opening web pages"),
  sidebarPanel(
    selectInput(inputId='test',label=1,choices=1:5)
  ),
  mainPanel(
    htmlOutput("inc")
  )
),
server = function(input, output) {
  getPage<-function() {
    return(tags$iframe(src = "http://www.bbc.co.uk"
                       , style="width:100%;",  frameborder="0"
                       ,id="iframe"
                       , height = "500px"))
  }
  output$inc<-renderUI({
    x <- input$test  
    getPage()
  })
})
)

【讨论】:

  • 但它显示为纯 html。大多数功能都给出“未找到”错误(如搜索)。有什么方法可以将它们作为 http 连接打开?
  • 您可以使用iframe 镜像页面。 www.google.com 和许多其他网站会发送一个 X-Frame-Options: SAMEORIGIN 标头,但是会阻止它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-11-27
  • 2021-10-18
  • 2011-10-31
  • 2012-01-04
  • 2013-11-07
  • 2020-04-27
  • 1970-01-01
相关资源
最近更新 更多