Hi
I am trying to embed a weather widget in my shiny app, using js code sourced from a url. I have found various sources online for this and, whilst I can get some widgets to work, the one I want to use doesn't seem to work.
The ui.R and server.R are shown below. There are two widget options used here. The first one displays, but the second one is blank. Any ideas as to how I get it to display, please?
I can get the second one to work by putting it directly into html code (i.e. outside a shiny app) but cannot understand why it doesn't work in the shiny app.
Any help would be much appreciated.
Many Thanks
David.
#ui.R
library(shiny)
shinyUI(fluidPage(
wellPanel(
htmlOutput("widget1")
),
wellPanel(
htmlOutput("widget2")
)
)
)
#server.R
library(shiny)
shinyServer(function(input, output) {
output$widget1<-renderText({
out1<-"<a class='weatherwidget-io' href='https://forecast7.com/en/51d51n0d13/london/' data-label_1='LONDON' data-label_2='WEATHER' data-theme='original' >LONDON WEATHER</a><script>"
out2<-"!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src='https://weatherwidget.io/js/widget.min.js';fjs.parentNode.insertBefore(js,fjs);}}(document,'script','weatherwidget-io-js');</script>"
out_all<-paste(out1,out2,"",sep="")
out_all
}
)
output$widget2<-renderText({
out4<-"<script type='text/javascript' src='https://darksky.net/widget/default/51.3055,-0.3072/us12/en.js?width=100%&height=350&title=ashtead, uk&textColor=333333&bgColor=FFFFFF&transparency=false&skyColor=333333&fontFamily=Default&customFont=&units=us&htColor=333333<Color=C7C7C7&displaySum=yes&displayHeader=yes'></script>"
out4
}
)
})