Add different pictures to each Markers in the Leaflet Package (Map Application)

You may want to tune your images, or perhaps use the width and height arguments of IMG tag more actively.

Consider this piece of code; note the use of single quotes to delimit strings, so that double quotes will remain safely inside (and utilized by the HTML call). Also note how I replaced the zero at the end of your link with a 1; a neat trick I found at https://support.exclaimer.com/hc/en-gb/articles/360018586691-How-to-host-an-image-using-Dropbox

library(sf)
library(dplyr)
library(leaflet)


a_point <- nominatimlite::geo_lite_sf("Clermont-Ferrand") %>% # looks about right
  mutate(label = paste0("lo & behold: a hedgehog",
                        '<img src=',
                        '"https://www.dropbox.com/s/9njtb9o9lql25o0/atelerix_algirus.jpg?dl=1"',
                        'alt="no longer stolen from wikipedia"',
                        'width="300"',
             #           'height="250"',
                        '>'))

leaflet(data = a_point) %>% 
  addProviderTiles("Esri.WorldImagery") %>% 
  addMarkers(popup = ~label) %>% 
  setView(lat = 50.073658, 14.418540, zoom = 4) # view centered on Prague (just because...)

2 Likes