简体   繁体   中英

Displaying html file using htmltools::tags$iframe in shiny is not working with renderUI()

This is my first question in StackOverflow. Please forgive me if the question is not represented in the proper format. I have a saved html widget, generated using flowmapblue.R that I want to display in a Markdown Shiny Document. I am using htmltools::tags$iframe to include the HTML file in the Shiny app. The file is kept under the www directory . For your kind reference, I am sharing the HTML file in the following LINK . The code that is working and giving desired result is:

---
title: "Flow Map"
author: "xyz"
date: "8/14/2020"
output: html_document
runtime: shiny
---

```{r flowmap, echo=FALSE, message=FALSE, warning=FALSE}
    titlePanel("Mobility Flow Map")
    mainPanel (htmltools::tags$iframe(src ="June_Spain.html", seamless="seamless", height=600, width="100%"))
```

I am getting this result Result without using renderUI . But actually my Markdown Shiny document will be responsive where the user can select zones and desired months. Based on those names the relevant HTML file will be selected. That's why I need to use the next following code snippet:

---
title: "Flow Map"
author: "xyz"
date: "8/14/2020"
output: html_document
runtime: shiny
---

```{r flowmap, echo=FALSE, message=FALSE, warning=FALSE}
    
titlePanel("Mobility Flow Map")
    mainPanel(
                htmlOutput("display_map")
             )
    output$display_map <- renderUI({
        my_test <-  htmltools::tags$iframe(src="June_Spain.html", seamless="seamless", height=600, width="100%")
        my_test
      })
```

In this case the HTML File is not Found as shown in Result using renderUI . I checked few similar problems with renderUI() and htmlOutput() but I couldn't make out where it is going wrong. I desperately need your help in this regard. Thanks in advance.

Strange. As a workaround you can encode the HTML to a base64 string:

b64 <- base64enc::dataURI(file = "www/June_Spain.html", mime = "text/html")
output$display_map <- renderUI({
  htmltools::tags$iframe(src=b64,  height=600, width="100%")
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM