r - 将天气 iframe 嵌入到 Shiny Dashboard 中

标签 r iframe shiny

我正在尝试将 Forecast.io 的天气预报嵌入到 Shiny 的仪表板中。我最初在使用 & 符号时遇到了麻烦,但看到一篇文章提供了如何使用特殊字符格式化 HTML 代码的示例。然而,当我运行该应用程序时,我看到一个简单的“未找到”,即使我知道该链接有效并且格式正确。我不确定我错过了什么。

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title = "Dashboard"),
  dashboardSidebar(
    sidebarMenu(
      menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard"))
    )
  ),

  dashboardBody(
    tabItems(
      # First tab content
      tabItem(tabName = "dashboard",
              fluidRow(

                column(12,
                       mainPanel(htmlOutput("frame")
                       )
                )
              )
      )
    )
  )
)

server <- shinyServer(function(input, output) {

  output$frame <- renderUI({
    tags$iframe(id = 'app', src = url("https://forecast.io/embed/#lat=42.3583&lon=-71.0603&name=Downtown Boston"), width = '100%')
  })

})

shinyApp(ui,server)

Screen capture of error in Shiny Dashboard

最佳答案

使用插入的仪表板进行更新

我将 url 从服务器传输到用户界面:

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
    dashboardHeader(title = "Dashboard"),
    dashboardSidebar(
        sidebarMenu(
            menuItem("Dashboard", 
                     tabName = "dashboard", 
                     icon = icon("dashboard")
            )
        )
    ),

    dashboardBody(
        tabItems(
            tabItem(
                tabName = "dashboard",
                fluidRow(
                    tags$iframe(
                        seamless = "seamless", 
                        src = "https://forecast.io/embed/#lat=42.3583&lon=-71.0603&name=Downtown Boston", 
                        height = 800, width = 1400
                    )
                )
            )
        )
    )
)

server <- function(input, output) {}
shinyApp(ui, server)

enter image description here

关于r - 将天气 iframe 嵌入到 Shiny Dashboard 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46307497/

相关文章:

internet-explorer - IE 在 iframe 页面 (SSL) 上悄悄地丢弃 cookies?

r - 将来自 shiny brushedPoints() 的输入转换为数据帧

css - 在 R Shiny 中更改 selectizeInput 选项的颜色

javascript - 帮助使用 jQuery 或 javascript 从 iFrame 获取元素

html - fancyapps 的 Fancybox3 | iFrame 调整大小

r - 使用 strsplit 正则表达式拆分文本

r - 将毫秒添加到 R 中的时间戳

r - 在 showModal 中使用 textOutput

r - dplyr Mutate 中的错误 - 遍历列以生成图形

r - 使用带有 cURL、RCurl 和 httr 的 cookie 发布请求