r – Adding an image to a leaflet map
I am hoping that someone could help me with this very challenging problem. I am trying to add an image to each plot on leaflet. Below is what I have so far. I got it down to creating the long and lat but the images part is where things fall apart. I know there’s a way to do it but putting the url but I’m hoping of using local images. Thanks!
df_Map <- data.frame(
win <- c("UW Milwaukee","Marquette University", "MSOE"),
loc <- c("Public", "Private", "Private"),
image <- c("R/WWW/UWM.JPG",
"R/WWW/MU.JPG",
"R/WWW/MSOE.JPG"),
lat <- c(43.07843930175696, 43.038417904138896, 43.045132486282874),
lon <- c(-87.88196860204758, -87.92926232373192, -87.90788583431048)
)
custom.labels <-paste0("<b>",df_Map$win,"</b><br>",
'<img src="', df_Map$image, '" alt="Location" width="75"><br>',
df_Map$loc)
#plotting of map
leaflet(df_Map) %>%
addTiles() %>%
addCircleMarkers(lng = ~lon,lat = ~lat,radius = df_Map$loc) %>%
addPopups(lng = ~lon,lat = ~lat,
popup = lapply( custom.labels, htmltools::HTML ),
options = popupOptions(closeButton = FALSE,autoPan =TRUE))
Read more here: Source link