3

I'm trying to use the leaflet package in R to produce an interactive map. Everything was working for me about a month ago, but now my map is appearing but I can't get the markers to appear. I tried using a simple example I found online but this has the same issue. I tried updating R, R studio, and all of my packages. I also tried the github development version of leaflet to no avail. Running this in an .Rmd file (also tried in a regular script). Please let me know if anyone has any ideas, thank you! My code:

library(leaflet)

leaflet() %>%
  addTiles() %>%  
  addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R")

My output:

enter image description here

I got the code from this site which shows what it's supposed to look like: https://rstudio.github.io/leaflet/

Session Info:

R version 4.1.3 (2022-03-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19044)

Matrix products: default

locale:
[3] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

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

other attached packages:
 [3] leaflet_2.1.0        lindia_0.9           ggannotate_0.1.0.900 shiny_1.7.1          esquisse_1.1.0       readxl_1.3.1        
 [7] haven_2.4.3          forcats_0.5.1        stringr_1.4.0        dplyr_1.0.8          purrr_0.3.4          readr_2.1.2         
[13] tidyr_1.2.0          tibble_3.1.6         ggplot2_3.3.5        tidyverse_1.3.1     

loaded via a namespace (and not attached):
  [3] colorspace_2.0-3       ellipsis_0.3.2         rio_0.5.29             rprojroot_2.0.2        parameters_0.17.0      fs_1.5.2              
  [7] mc2d_0.1-21            rstudioapi_0.13        farver_2.1.0           remotes_2.4.2          ggrepel_0.9.1          DT_0.21               
 [13] fansi_1.0.2            mvtnorm_1.1-3          lubridate_1.8.0        xml2_1.3.3             splines_4.1.3          cachem_1.0.6          
 [19] knitr_1.37             pkgload_1.2.4          zeallot_0.1.0          jsonlite_1.8.0         broom_0.7.12           dbplyr_2.1.1          
 [25] ggdist_3.1.1           clipr_0.8.0            compiler_4.1.3         httr_1.4.2             backports_1.4.1        assertthat_0.2.1      
 [31] Matrix_1.4-0           fastmap_1.1.0          cli_3.2.0              later_1.3.0            prettyunits_1.1.1      htmltools_0.5.2       
 [37] tools_4.1.3            ggstatsplot_0.9.1      gtable_0.3.0           glue_1.6.2             Rcpp_1.0.8.3           cellranger_1.1.0      
 [43] jquerylib_0.1.4        vctrs_0.3.8            nlme_3.1-155           crosstalk_1.2.0        insight_0.16.0         xfun_0.30             
 [49] brio_1.1.3             ps_1.6.0               testthat_3.1.2         openxlsx_4.2.5         rvest_1.0.2            mime_0.12             
 [55] miniUI_0.1.1.1         lifecycle_1.0.1        devtools_2.4.3         MASS_7.3-55            scales_1.1.1           hms_1.1.1             
 [61] promises_1.2.0.1       rematch2_2.1.2         RColorBrewer_1.1-2     yaml_2.3.5             curl_4.3.2             memoise_2.0.1         
 [67] gridExtra_2.3          datamods_1.2.0         sass_0.4.0             reshape_0.8.8          stringi_1.7.6          paletteer_1.4.0       
 [73] bayestestR_0.11.5      desc_1.4.1             pkgbuild_1.3.1         zip_2.2.0              rlang_1.0.2            pkgconfig_2.0.3       
 [79] distributional_0.3.0   lattice_0.20-45        patchwork_1.1.1        htmlwidgets_1.5.4      labeling_0.4.2         processx_3.5.2        
 [85] tidyselect_1.1.2       plyr_1.8.6             magrittr_2.0.2         R6_2.5.1               generics_0.1.2         DBI_1.1.2             
 [91] pillar_1.7.0           foreign_0.8-82         withr_2.5.0            mgcv_1.8-39            datawizard_0.3.0       performance_0.8.0     
 [97] modelr_0.1.8           crayon_1.5.0           WRS2_1.1-3             shinyWidgets_0.6.4     utf8_1.2.2             correlation_0.8.0     
[103] tzdb_0.2.0             usethis_2.1.5          grid_4.1.3             data.table_1.14.2      callr_3.7.0            reprex_2.0.1          
[109] digest_0.6.29          xtable_1.8-4           httpuv_1.6.5           statsExpressions_1.3.0 munsell_0.5.0          viridisLite_0.4.0     
lovalery
  • 4,524
  • 3
  • 14
  • 28
Stephanie
  • 31
  • 2
  • 1
    Hi Stephanie, welcome to SO! Well, `leaflet` doesn't seem to behave as expected... and apparently we are not the only ones facing this problem as it has been reported on github two days ago... So, please find here the [link](https://github.com/rstudio/leaflet/issues/782) in case the solution appears on github first. Cheers. – lovalery Mar 18 '22 at 20:28
  • 1
    Hi Stephanie, the problem has been fixed in the latest version of `leaflet`. So, you can now upgrade the `leaflet` library to version `2.1.1` from `CRAN` and it will work. Cheers. – lovalery Mar 24 '22 at 12:57
  • 1
    Thank you for your comments @lovalery! It's working for me now – Stephanie Mar 25 '22 at 15:01

1 Answers1

0

I had the same result, and search for other example.

This one works

library(leaflet)

data(quakes)

leaflet(quakes) %>% addTiles() %>% addMarkers( clusterOptions = markerClusterOptions() )

Kennett01
  • 1
  • 2
  • This isn't really an answer, just an example of code that works. This would be more appropriate as a comment (though you can't comment because of your rep). I would suggest deleting this non-answer. – Josh Mar 19 '22 at 21:53