Open gregmacfarlane opened 2 years ago
Thanks for the report.
Regarding issue 1
Error: path for html_dependency not found: /var/folders/0f/f4v60fbn6psdh5r_wlqz0qvm0000gn/T//RtmpsCf5pj
It seems the html dependency is downloaded / put into a temp folder for the R session. Using new_session: true
will run each file in a different R session, so this can cause issue. I am surprised that it happens only now. I'll see if there were some changes somewhere.
Regarding issue2, we'll see after understanding more about issue 1, unless it happens also when new_session: false
I am surprised that it happens only now.
I'm surprised, too. I did save and restore the HTML dependencies: https://github.com/rstudio/bookdown/blob/169c43b6bb95213f2af63a95acd4e977a58a3e1f/R/render.R#L225 Not sure why or when that stopped working.
So after debugging, here is the story:
Traceback for the issue is this one:
<error/rlang_error>
Error:
! path for html_dependency not found: C:/Users/chris/AppData/Local/Temp/Rtmpk1vYTY
---
Backtrace:
1. bookdown::render_book()
2. bookdown:::render_new_session(...)
3. rmarkdown::render(...)
4. output_format$pre_processor(...)
5. rmarkdown base(...)
6. rmarkdown:::html_extras_for_document(...)
7. rmarkdown dependency_resolver(all_dependencies)
8. base::lapply(dependencies, validate_html_dependency)
9. rmarkdown FUN(X[[i]], ...)
10. rmarkdown:::stop2("path for html_dependency not found: ", file)
Run `rlang::last_trace()` to see the full context.
So issue happens during validation of dependencies in rmarkdown where we check for file existence when a src$file
dependency is provided
https://github.com/rstudio/rmarkdown/blob/1ca8a87cc9a6bd009543e636cbd1f253c8d5539f/R/html_dependencies.R#L374
When using leaflet::addProvidersTiles()
, it will load a specific HTML dependencies that leaflet creates in a R temp folder
https://github.com/rstudio/leaflet/blob/main/R/plugin-providers.R#L92-L107
This lead to this html dependencies that will be validated by R Markdown:
List of 10
$ name : chr "leaflet-providers"
$ version : chr "1.9.0"
$ src :List of 1
..$ file: chr "C:/Users/chris/AppData/Local/Temp/Rtmp618RtY"
$ meta : NULL
$ script : chr "leaflet-providers_1.9.0.js"
$ stylesheet: NULL
$ head : NULL
$ attachment: NULL
$ package : NULL
$ all_files : logi FALSE
- attr(*, "class")= chr "html_dependency"
This temp folder is the one that was set from the R session where the Rmd file containing the leaflet code was knitted. So at the validation stage, it does not exist anymore.
I don't really know if this is expected that leaflet is setting a dependency in an absolute path which is temporary to a R session. Doesn't seem so right, but could be understandable when used in an R session. Probably we should handle this better on our side.
Regarding why not before: We have touch this validate_html_dependency
function in https://github.com/rstudio/rmarkdown/pull/2151 so maybe we missed a edge case.
@yihui do you have insights on this ?
Thanks for looking into this. As far as I can tell, the issue with leaflet maps not being included in the output HTML only occurs when the output document is renamed and new_session: yes
@cderv Oh, this reminded me that I had investigated this issue two years ago, which I have totally forgotten: https://github.com/rstudio/bookdown/issues/15#issuecomment-573776659 I'm afraid that this won't be easy to fix for new_session: yes
...
Oh thanks. Did not thought to look into old issues. I think our best shots is to work with our colleague on leaflet to stabilize the dependency. I'll see what we can do on leaflet side.
@gregmacfarlane unfortunately current state is that the tile provides feature of leaflet won't work with bookdown knit and merge approach. You'll have to use new_session: false
.
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
new_session
bookdown parameter, which determines whether eachRmd
file should be rendered in a new R session.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
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: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 aleaflet
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: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