首页 > 解决方案 > 如何在闪亮的应用程序中显示外部网站?

问题描述

我正在尝试将 URL 连接到左侧 sidebarMenu 中的 menuSubItem,因此如果单击该项目,它将在右侧空白页面中显示网页。我已经尝试tags$iframe或简单地放入a(href="")UI,但都失败了。下面是我在 UI 中的示例代码。

```
sidebar<- dashboardSidebar(
sidebarMenu(id = "tabs",
          menuItem("Homepage", tabName = "homepage", icon = icon("home")),
          menuItem("Liability Distribution", tabName = "liab_dist",
                   menuSubItem("Google", tabName = "Google", icon = icon("angle-right"))))) 
body<-dashboardBody(
  tabItems(
    #Google
    tabItem(tabName = "Google", 
            fluidRow(
              tags$iframe(
                seamless = "seamless",
                src = "http://google.com",
                height = 800, width = 1400)))))

标签: rshiny

解决方案


您的代码没有任何问题 - 处理 iframe 时只有两个警告:1.) RStudio 不加载外部资源 - 猜测是为了安全。但是一旦你运行你闪亮的应用程序,你就会得到这样的输出:Listening on http://127.0.0.1:7572. 当您粘贴http:...到 Chrome(或 Firefox 或您喜欢的浏览器)中的新标签页时,大多数情况下您会得到一些内容。谷歌是一个例外(还有更多),因为 2.)一些网站告诉浏览器不要在 iframe 中显示它们(当你在 Chrome 中打开 devtools 访问 google.com 时(或再次:Firefox 或你最喜欢的) , 你会看到的x-frame-options: SAMEORIGIN作为响应头。所以你在这里不走运 - 但​​我建议尝试使用你的个人博客或你知道允许 iFrames 的某些页面。只要你打开除了 RStudio 的 Shiny 预览之外的任何东西,你很可能会得到一个结果。


推荐阅读