leaflet icon indicating copy to clipboard operation
leaflet copied to clipboard

Easybutton: use icon from directory

Open arthurgailes opened this issue 5 years ago • 5 comments

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!

arthurgailes avatar Oct 09 '18 15:10 arthurgailes

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);}")))

trafficonese avatar Oct 09 '18 16:10 trafficonese

Thanks! This works really well with online images, but doesn't seem to work on a local directory.

arthurgailes avatar Oct 09 '18 16:10 arthurgailes

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.

bTEND avatar Jan 11 '19 07:01 bTEND

I'm having this issue as well with a local file. @bTEND I'm not clear on your fix.

jzadra avatar Dec 03 '21 19:12 jzadra

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">',

trafficonese avatar Jul 24 '23 11:07 trafficonese