I am currently fighting trying to get knitr to render my leaflet maps, taken from a collection to appear correctly in a rendered RMD html-output. I\'m already aware about some p
You need to put things in a tagList, and have that list print from the chunk. This just uses default settings for fig.show
and results
; it also uses the htmltools::h3()
function to turn the title into an HTML title directly, not using the Markdown ###
marker. (You might want h2
or h4
instead.)
---
title: "test3"
output: html_document
---
```{r setup, include=FALSE}
library(leaflet)
library(htmltools)
knitr::opts_chunk$set(echo = TRUE)
```
## Title 1
```{r echo=FALSE}
html <- list()
for (i in 1:4) {
html <- c(html,
list(h3(paste0("Map Number ", i)),
leaflet() %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")
)
)
}
tagList(html)
```