Problem when viewing html generated by Leaflet

leaflet

#1

Hi, I have created an interactive map using OpenStreetMap as background tile and also include popup for all the circles as well as a color scale legend. I then go to Export->Save as Web Page to save it as a html.

However, when open up the html, the Map tile can not be loaded and seen while all the other elements are ok. Does any one knows why and how can I deliver the result so the map can be seen independent of R studio?

Many Thanks


#2

Without your code, I guess this can solve your problem:

addTiles('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png')

I hope this will help you.


#3

If you need to deliver the leaflet map as a standalone html you sholud use saveWidget function from htmlwidgets package.


#4

Are you sure that your Internet connection is fine?


#5

Hi Paul, thanks for you reply. Below is the part of my code generating the map widget. OpenStreetMap is the default map tile so I did not claim it explicitly, I tried to replace the 2nd line with yours (with “%>%” to the end) but it did not work either.

m <- leaflet(f171028_sub) %>%
  addTiles() %>%  # Add default OpenStreetMap map tiles
  addCircles(lng = ~ lng, lat = ~lat, popup = ~popup, radius = 0.25, color = ~pal(disp2), opacity = 0.75) %>% 
  addLegend("bottomright", pal = pal, values = -15:15,
          title = "Ground Movement (mm)",
          opacity = 1
          )

#6

Yes. the internet is ok. Every element shows well in Rstudio Viewer


#7

I tried to load htmlwidets package and then try the code below but got an error message

saveWidget(m,“testing.html”)
Error in system(paste(shQuote(pandoc_path), “–version”), intern = TRUE) :
’“C:/Users/zhangwei.ning/AppData/Local/Continuum/Anaconda3/Library/bin/pandoc”’ not found


#8

Maybe you can try a reinstallation of pandoc, because:

from htmlwidget

f (!pandoc_available()) {
stop(“Saving a widget with selfcontained = TRUE requires pandoc. For details see:\n”,
https://github.com/rstudio/rmarkdown/blob/master/PANDOC.md”)
}

If you have not pandoc installed it should break in that stop and show you the message, perhaps pandoc installation got corrupted. So I would try the pandoc installation


#9

@zning, could try the code below?

Here, the tile appears normally in browsers (firefox and crhome).

library(ggmap)
library(leaflet)
library(htmlwidgets)

br <- geocode("Fortaleza - Brazil")

l <- leaflet(br) %>% 
 addTiles('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png') %>% 
 addMarkers()

saveWidget(l, 'leaflet.html')