I\'ve created a R markdown report where the sections and tabsets are dynamically created.
I have an issue where the Leaflet maps are not being generated in the output
This is a similar problem as described here with Highcharter
Try:
---
title: "Test Leaflet Tabs"
output: html_document
---
`r knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE, cache = F)`
```{r setup, include=FALSE}
library(leaflet)
leaflet()
```
```{r,results='asis'}
filtered_list <- 1:3
cat("## Tabs {.tabset .tabset-fade .tabset-pills}", "\n")
for (estates in filtered_list){
cat("###", estates, "\n")
cat("\n\n\n")
cat("This is where the map will go ")
# generate leaflet plot (doesn't even show white space if not stored in tagList)
page <- htmltools::tagList(
leaflet() %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")
)
cat(as.character(page))
}
```
I had a similar issue that was solved by putting the leaflet into a widget frame.
l <- leaflet() %>%
addTiles() %>%
addMarkers(map_data$Longitude, map_data$Latitude)
widgetframe::frameWidget(l, width = "100%")
This has the effect of saving html tiles for use in rendering. I'm pretty sure it just wraps the leaflet in a HMTL tag.