How to resize large images in R Leaflet marker popups?

647 views Asked by At

My code:

library(leaflet)

df   <- as.data.frame(read.csv("arts.csv"))
file <- as.character(df$url)

leaflet() %>% addTiles() 
          %>% addMarkers(data = df, lng = ~lon, lat = ~lat, 
                         popup = paste0("<img src = ", file, ">")) 
          %>% popupOptions(maxWidth = "auto")

I used some code snippet from here: Image in R Leaflet marker popups

My question is: how can I easily resize large images appearing in popups?

The illustartion of the problem: For Example, I would like to make this photo of Cave Rapa Nui smaller to fit the pop-up.

For Example, I would like to make this photo of Cave Rapa Nui smaller to fit the pop-up.

Thank you in advance!

1

There are 1 answers

1
help-info.de On BEST ANSWER

You can adjust the size by using the HTML width attribute.

Edit your code from above to e.g.

map <- leaflet() %>% 
           addTiles() %>%
           addMarkers(data = df,
                      lng = ~lon,
                      lat = ~lat,
                      popup = paste0("<img src = ", file, " width = 300>"))

map  # print the map

enter image description here