0

I've run into a problem: I'm trying to display a widget in my Shiny app. The HTML that I'm trying to embed runs perfectly if I save it and view it. It also runs fine on a HTML viewer. When I insert the HTML into my UI, it doesn't show up. I suspect it is because it contains a <script> tag.

I've tried wrapping the HTML with tags$div(HTML()) as well as includeScript(path = myhtml.html) (with and without wrapping the HTML in <body></body>). Nothing seems to produce results.

Any ideas? Thanks very much.

Here's my HTML:

 <a
  class="weatherwidget-io"
  href="https://forecast7.com/en/40d71n74d01/new-york/"
  data-label_1="New York"
  data-label_2="Weather"
  data-font="Fira Sans"
  data-days="3"
  data-theme="weather_one"
  >My Weather</a
 >
 <script>
!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>

Edit: Here's a sample app doing exactly what I'm trying to: When I run it it's blank.

library(shiny)

ui <- fluidPage(

    tags$div(HTML("<a
                    class=\"weatherwidget-io\"
                    href=\"https://forecast7.com/en/40d71n74d01/new-york/\"
                    data-label_1=\"New York\"
                    data-label_2=\"Weather\"
                    data-font=\"Fira Sans\"
                    data-days=\"3\"
                    data-theme=\"weather_one\"
                    >Saint George Canadawide Sports HQ</a
                    >
                      <script type=\"text/javascript\">
                      !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>")))

server <- function(input, output) {
    
}

# Run the application 
shinyApp(ui = ui, server = server)
JStorey
  • 13
  • 1
  • 4
  • Can you please show how you tried to include it in your actual shiny app? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick Jul 02 '21 at 03:53
  • @MrFlick Thanks for your response. I've edited the original post with an example app. – JStorey Jul 02 '21 at 04:01
  • Are you just testing in the RStudio viewer? Try the option to "Open in Browser" instead. I think there might be security issues with the RStudio viewing loading https content in an iframe. – MrFlick Jul 02 '21 at 04:21
  • Woah. Thank you! Can't believe it was that simple. I presume it will display okay when I publish it to ShinyApp.io as well? Really appreciate your help! Thanks again! – JStorey Jul 02 '21 at 04:26

0 Answers0