Description
I have a book written in Bookdown, in which I would like to include Leaflet maps. I have noticed that my ability to print these maps in the interactive html is a function of
- the value of the
new_session
bookdown parameter, which determines whether eachRmd
file should be rendered in a new R session. - the use of the
book_filename
bookdown parameter.
Perhaps these are two completely separate issues, but I discovered one while looking for the other and I don't know how intertwined they are.
MWE
---
title: "A Book"
author: "Frida Gomam"
site: bookdown::bookdown_site
documentclass: book
output:
bookdown::gitbook: default
#bookdown::pdf_book: default
---
# Test
```{r setup}
library(leaflet)
```
Don't miss Figure \@ref(fig:nice-tab).
```{r nice-tab, fig.cap="Figure"}
leaflet() %>%
addProviderTiles(providers$CartoDB) %>%
addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")
```
As posted, this renders correctly (as expected) using bookdown::render_book()
.
Issue 1: HTML dependency based on background layer
If I render as bookdown::render_book(new_session = TRUE)
however, I get the following error:
Error: path for html_dependency not found: /var/folders/0f/f4v60fbn6psdh5r_wlqz0qvm0000gn/T//RtmpsCf5pj
Please delete _main.md after you finish debugging the error.
This persists even after clearing the knitr cache and restarting R, as suggested on StackOverflow
I can avoid this error, however, by using a different map tiles layer. I feel like this is a bookdown
issue and not a leaflet
issue because the performance changes based on a bookdown flag.
Issue 2: Not printing leaflet with named file
If I call the build using bookdown::render_book(config_file = "_bookdown.yml")
and alter the name following _bookdown.yml
config file:
new_session: yes
book_filename: "mydoc.Rmd"
then the leaflet map is completely empty, regardless of the background map used.
Viewing the page in the debugger shows that there is an htmlwidget in the proper place, but I don't know enough to tell where exactly this is a problem.
session info
R version 4.2.0 (2022-04-22)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.3.1, RStudio 2022.2.1.461
Locale: en_US.UTF-8 / en_US.UTF-8 / en_US.UTF-8 / C / en_US.UTF-8 / en_US.UTF-8
Package version:
base64enc_0.1.3 bookdown_0.26.3 bslib_0.3.1 digest_0.6.29 evaluate_0.15
fastmap_1.1.0 fs_1.5.2 glue_1.6.2 graphics_4.2.0 grDevices_4.2.0
highr_0.9 htmltools_0.5.2 jquerylib_0.1.4 jsonlite_1.8.0 knitr_1.39
magrittr_2.0.3 methods_4.2.0 R6_2.5.1 rappdirs_0.3.3 rlang_1.0.2
rmarkdown_2.14 sass_0.4.1 stats_4.2.0 stringi_1.7.6 stringr_1.4.0
tinytex_0.39 tools_4.2.0 utils_4.2.0 xfun_0.31 yaml_2.3.5
Metadata
Metadata
Assignees
Type
Projects
Status