Not able to make RMarkdown html output showing interective Tmap views (tmap_mode set to "view") while printed inside for cycle. Any tips?
This works properly:
```{r interactive maps, echo=FALSE, message=FALSE, warning=FALSE, results='asis'}
library(pander)
library(knitr)
library(tmap)
data("World")
tmap_mode("view")
map_1 <- tm_shape(World) +
tm_polygons("HPI")
map_2 <- tm_shape(World) +
tm_polygons("economy")
map_3 <- tm_shape(World) +
tm_polygons("footprint")
maps <- list(map_1, map_2, map_3)
pandoc.header(("Map n° 1"), level = 3)
maps[[1]]
pandoc.header(("Map n° 2"), level = 3)
maps[[2]]
pandoc.header(("Map n° 3"), level = 3)
maps[[3]]
```
How html document exported from Markdown appers (avoiding use for loop):

This doesn't... The problem seems for loop doesn't give back properly tmap widgets...
```{r interactive maps from cycle, echo=FALSE, message=FALSE, warning=FALSE, results='asis'}
library(pander)
library(knitr)
library(tmap)
data("World")
tmap_mode("view")
map_1 <- tm_shape(World) +
tm_polygons("HPI")
map_2 <- tm_shape(World) +
tm_polygons("economy")
map_3 <- tm_shape(World) +
tm_polygons("footprint")
maps <- list(map_1, map_2, map_3)
for (i in 1:length(maps)) {
pandoc.header(paste("Map n°", i), level = 3)
print(maps[[i]])
cat("\n")
}
```
How html document exported from Markdown appers (using for loop):

try this: