I found this post on stackoverflow to make an interactive map in R (second answer):
But for some reason, when I try to search for one of the locations (e.g. "location 1") - the map seems to take a long time to load and experience a lot of lag. As such, I have waited several minutes and was unable to actually search for one of these cities.
Can someone please help me figure out what I am doing wrong?
Thank you!
CodePudding user response:
The problem occurs when there is no label given for the locations.
library(leaflet)
library(inlmisc)
df <- read.csv(textConnection(
'Name, Lat, Long, Label,
<b>location 1</b>,42.3401, -71.0589, Loc 1
<b>location 2</b>,42.3501, -71.0689, Loc 2'))
map <- leaflet(df) %>%
addTiles() %>%
setView(lng=-71.0589,lat=42.3301, zoom=12) %>%
addMarkers(~Long, ~Lat, popup = ~Name, group="marker", label = ~Label) %>%
inlmisc::AddSearchButton(group = "marker", zoom = 15,
textPlaceholder = "Search here")