2

I am trying to embed the weather forecast from forecast.io in a Shiny dashboard. I originally had trouble with the ampersand but saw a post that provided an example of how to format HTML code with special characters. However, when I run the app I see a simple "Not Found", even though I know that the link works and is being formatted correctly. I'm not sure what I'm missing.

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

nicktb
  • 23
  • 1
  • 3

1 Answers1

4

Update with inserted dashboard

I transfered url from server to 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

pogibas
  • 27,303
  • 19
  • 84
  • 117
  • thanks for your note but it didn't work for me. On the dashboard page it just shows a URL link that says "My Url" that takes me to the forecast. Admittedly an improvement from "Not Found" but not the embeddedness I was hoping for. I haven't had any luck embedding any iframes (even using scripts from other examples), so I'm thinking it's something systemic. – nicktb Sep 21 '17 at 23:35
  • This is great, @PoGibas! Thanks! It shows up when I open it in the browser, but not when I just run the application, so I'll keep that in mind when trying iframes again in the future. Thank you! – nicktb Sep 25 '17 at 17:11