将天气iframe嵌入Shiny Dashboard

时间:2017-09-19 18:31:23

标签: r iframe shiny

我正在尝试将forecast.io中的天气预报嵌入Shiny仪表板中。我最初在&符号上遇到了麻烦,但看了一篇帖子,提供了一个如何使用特殊字符格式化HTML代码的示例。但是,当我运行应用程序时,我看到一个简单的" Not Found",即使我知道链接正常并且格式正确。我不确定我错过了什么。

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

1 个答案:

答案 0 :(得分:2)

使用已插入的信息中心进行更新

我将url从服务器转移到了ui:

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