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, Read local HTML file into R, I learned how to import these html files back into R:
library(xml2)
rawHTML1 <- read_html(x = "m1.html")
# etc
I now want to directly load these html files into a dashboard in R. Here is the dashboard code:
---
title: "maps"
output: flexdashboard::flex_dashboard
---
```{r setup, include=FALSE}
#library(flexdashboard)
library(leaflet)
library(xml2)
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)
```
Column {.tabset}
-------------------------------------
### map 1
```{r}
rawHTML1 <- read_html(x = "m1.html")
rawHTML1
```
### map 2
```{r}
rawHTML2 <- read_html(x = "m2.html")
rawHTML2
```
### map 3
```{r}
rawHTML3 <- read_html(x = "m3.html")
rawHTML3
```
### map 4
```{r}
rawHTML4 <- read_html(x = "m4.html")
rawHTML4
But the resulting dashboard is not loading the maps correctly:
- 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!