Home > Back-end >  Directly Loading HTML files in R?
Directly Loading HTML files in R?

Time:08-25

I made the following 4 maps in R:

library(leaflet)
library(leaflet.extras)
id = 1:1000
long = 2.2945   rnorm( 1000, 0.1085246 , 0.1)
lat = 48.8584   rnorm( 1000, 0.009036273 , 0.1)
my_data_1 = data.frame(id, lat, long)
id = 1:1000
long = 2.2945   rnorm( 1000, 0.1085246 , 0.1)
lat = 48.8584   rnorm( 1000, 0.009036273 , 0.1)
my_data_2 = data.frame(id, lat, long)


map1 = my_data_1 %>%
    leaflet() %>%
    addTiles() %>%
    addHeatmap(lng=~long,lat=~lat,max=100,radius=20,blur=10)

map2 = my_data_2 %>%
    leaflet() %>%
    addTiles() %>%
    addHeatmap(lng=~long,lat=~lat,max=100,radius=20,blur=10)

map3 = my_data_1 %>% 
    leaflet() %>% 
    addTiles() %>% 
    addMarkers(clusterOption=markerClusterOptions())

map4 = my_data_2 %>% 
    leaflet() %>% 
    addTiles() %>% 
    addMarkers(clusterOption=markerClusterOptions())

I then saved each of these maps as an html file:

library(htmltools)
library(htmlwidgets)
library(plotly)

htmlwidgets::saveWidget(as_widget(map1), "m1.html")
htmlwidgets::saveWidget(as_widget(map2), "m2.html")
htmlwidgets::saveWidget(as_widget(map3), "m3.html")
htmlwidgets::saveWidget(as_widget(map4), "m4.html")

Based on the instructions in the following post, enter image description here

  • Does anyone know how to fix this problem?

I know that I can create the maps themselves in the rmarkdown/dashboard, but I would like to see if there is a way to directly load a pre-existing html version of the maps into the dashboard. Is this possible?

Thank you!

CodePudding user response:

You can include it using <object>

Column {.tabset}
-------------------------------------
   
### map 1

<object type="text/html" data="m1.html"></object>

### map 2

<object type="text/html" data="m2.html"></object>

### map 3

<object type="text/html" data="m3.html"></object>

enter image description here


You can change size of the object like this:

<object type="text/html" data="m1.html" width="700" height="300"></object>
  • Related