Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leaflet Map not rendering in Rmarkdown, R Notebook when opened in browser

Tags:

r

rstudio

leaflet

For some reason, I can view the leaflet map in the RStudio viewer, but not in a browser, even a very basic map.

```{r, echo=FALSE, warning=FALSE}
library(leaflet)
m <- leaflet() %>% addTiles()
m
```

All other images appear no problem when viewing the HTML file in the browser, but the map won't. Anybody run into this problem before?

like image 847
Martin Boros Avatar asked Oct 29 '22 22:10

Martin Boros


1 Answers

There is something wrong with the default tiles set. Try this:

```{r, echo=FALSE, warning=FALSE}
library(leaflet)
m <- leaflet() %>% addTiles(urlTemplate = 'http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png')
m
```

You can find a good resource here for alternative third-party tiles.

like image 175
Samuel Avatar answered Nov 09 '22 13:11

Samuel