Search code examples
rr-leaflet

leaflet works in R but not in browser


The following code works in R but not in the browser.

library(leaflet)
data(quakes)

map = leaflet(data = quakes[1:20,]) %>% 
      addTiles() %>%
      addMarkers(~long, ~lat, 
          popup = ~as.character(mag), label = ~as.character(mag))

The browser only shows the location of the markers. I have disabled all browser extensions.

enter image description here

Question: how can I show the underlying map?

Session info:

R version 3.3.3 (2017-03-06)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Linux Mint 18.1

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] leaflet_1.1.0

loaded via a namespace (and not attached):
 [1] htmlwidgets_0.8 shiny_1.0.0     magrittr_1.5    R6_2.2.0        htmltools_0.3.5 tools_3.3.3     Rcpp_0.12.10    crosstalk_1.0.0 digest_0.6.12   xtable_1.8-2    httpuv_1.3.3    mime_0.5   

Solution

  • There appears to be an error getting the map tiles from the default map tile provider.

    Until this is corrected in the leaflet package, I would suggest using another map tile provider for example:

    map = leaflet(quakes[1:20,]) %>% 
    addProviderTiles(providers$Esri.NatGeoWorldMap) %>% 
      addMarkers(~long, ~lat, 
                 popup = ~as.character(mag), label = ~as.character(mag))
    map
    

    A full list of available map tile providers is available here: http://leaflet-extras.github.io/leaflet-providers/preview/index.html