Leaflet not rendering in dynamically generated R markdown html knitr

后端 未结 2 1405
说谎
说谎 2021-01-16 16:23

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

2条回答
  •  甜味超标
    2021-01-16 17:07

    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))
        }
    ```
    
    

提交回复
热议问题