leaflet
leaflet copied to clipboard
Easybutton: use icon from directory
Hello,
I'd like to add my own icon into R's leaflet easyButton function as below, but when I give the text of my directory, the button simply shows up blank. The documentation doesn't make it clear whether this is possible.
leaflet() %>% addTiles() %>%
addEasyButton(easyButton(
icon='mydir/mypic.png', title='Zoom to Level 1',
onClick=JS("function(btn, map){ map.setZoom(1);}")))
Thank you!
You could include an image like that. This should work with local images too. Make sure to give an appropriate width and height.
leaflet() %>% addTiles() %>%
addEasyButton(easyButton(
icon='<img src="https://cabotwealth.com/wp-content/uploads/cabot-hand-dirt-leaf.jpg" width="100%" height="100%">',
title='Zoom to Level 1',
onClick=JS("function(btn, map){ map.setZoom(1);}")))
Thanks! This works really well with online images, but doesn't seem to work on a local directory.
Hello,
I sufferer last night with exact same problem. The solution came this morning when i read your post. it is working on local directory - the question is what is your "local directory". So i make nodejs project and use parcel - so working directory in this case is /dist!!!!! not your production directory where you place working files. When move my /res to /dist the magic is happen.
I'm having this issue as well with a local file. @bTEND I'm not clear on your fix.
In a shiny app, you can put the icon in the www
folder and use it like this:
icon='<img src="./someicon.svg" width="20px" height="20px">',