leaflet icon indicating copy to clipboard operation
leaflet copied to clipboard

Added option to addProviderTiles() for user to specify .js file location

Open jaredlander opened this issue 3 years ago • 3 comments

When calling addProviderTiles, JavaScript is written to a temp file. This does not persist when using Quarto (but it has in the past with regular rmarkdown). So I added an option in addProviderTile (along with subsequently called functions) for the user to specify a location to write that JavaScript file. This fixed the problem for a presentation I am working on that has many called to addProviderTiles.

Minimal reproducible example

library(leaflet)

# this is the inst folder for leaflet
pop <- sf::read_sf('inst/csv/uspop2000.csv') |> 
  sf::st_as_sf(coords=c('Long', 'Lat'), remove=FALSE)

leaflet() |> 
  addProviderTiles('CartoDB.Voyager', dependencyLocation='~') |> 
  addCircles(data=pop)

PR task list:

  • [X ] Update NEWS
  • [ ] Add tests (where appropriate)
    • R code tests: tests/testthat/
    • Visual tests: R/zzz_viztest.R
  • [ X] Update documentation with devtools::document()

jaredlander avatar May 16 '22 05:05 jaredlander

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar May 16 '22 05:05 CLAassistant

I'll admit this is not a pretty solution, but it got the job done. Maybe something nicer will be to automatically write somewhere other than tempdir(). Or perhaps include the JavaScript as an R object rather than a file, but I don't know if that's possible given the JavaScript that needs to be invoked.

jaredlander avatar May 16 '22 05:05 jaredlander

Turns out this problem also creates issues for regular rmarkdown documents that use caching. When using addProviderTiles() extensively last year this wasn't a problem, so there must have been a change somewhere in the past year that puts the downloaded javascript files somewhere (/tmp) that doesn't survive renders.

jaredlander avatar Jul 07 '22 02:07 jaredlander

Closing in favor of #884

schloerke avatar Oct 13 '23 14:10 schloerke