tuttifolies tuttifolies - 9 months ago 103
R Question

image not displaying in html string for addControl() from leaflet in R

I have the following code

myicon <- makeIcon( iconUrl = "myicon.ico" )
html_legend <- "<img src='myicon.ico'>hey<br/>"
map_leaflet <- leaflet() %>%
addTiles() %>%
addMarkers(50, 50, icon = myicon, popup = paste("geo")) %>%
addControl(html = html_legend, position = "bottomright")

The map is correct, the icon on the map is good, and the popup as well.

I want to display the icon as a legend. It displays the "question mark error icon" and not the actual image. On the other hand the word "hey" do appear.

Thank you in advance for your help. I do not understand what is missing.

Answer Source

The question mark error icon means that it cannot find your image.

This is normal since during creation Leaflet is not running on a webserver. When you place your generated HTML-file on a webserver and the image icon in the appropriate place it will work.

I did this myself. Same error icon and worked like a charm when I placed it on the webserver. A page that uses the same trick.