rstudio / leaflet

R Interface to Leaflet Maps

Home Page:http://rstudio.github.io/leaflet/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

htmlwidgets 1.6.3 breaks addEasyButton

SpeckledJim2 opened this issue · comments

commented

The code below is one of the addEasyButton leaflet examples in the help file.

The code runs fine with htmlwidgets v1.6.2, but doesn't run under v1.6.3 - the easy button does not appear. The v.1.6.3 documentation refers to a potentially breaking change - reproduced below:

Potentially breaking changes

Closed #466: htmlwidgets no longer recurses into list-like objects when searching for JavaScript strings wrapped in JS(), unless the object has the class "list" or "data.frame". This stops htmlwidgets from (possibly infinitely) recursively searching objects that are not actually recursive. Widget authors who relied on the previous behavior should ensure that their widget's JS() calls are wrapped in objects that have the class "list" or "data.frame". (#467)

library(leaflet)

leaf <- leaflet() %>%
  addTiles() %>%
  addEasyButton(easyButton(
    icon = htmltools::span(class = "star", htmltools::HTML("&starf;")),
    onClick = JS("function(btn, map){ map.setZoom(1);}")))
leaf

sessionInfo() output

R version 4.3.1 (2023-06-16)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.3 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3 
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so;  LAPACK version 3.10.0

locale:
 [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C               LC_TIME=en_GB.UTF-8       
 [4] LC_COLLATE=en_GB.UTF-8     LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
 [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       

time zone: Europe/London
tzcode source: system (glibc)

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] leaflet_2.2.1

loaded via a namespace (and not attached):
 [1] htmlwidgets_1.6.3 compiler_4.3.1    ellipsis_0.3.2    magrittr_2.0.3    fastmap_1.1.1    
 [6] R6_2.5.1          cli_3.6.1         htmltools_0.5.7   tools_4.3.1       rstudioapi_0.15.0
[11] jquerylib_0.1.4   crosstalk_1.2.1   jsonlite_1.8.7    digest_0.6.33     rlang_1.1.2  

The latest htmlwidgets release undoes this breaking change