Skip to content Skip to sidebar Skip to footer

R Leaflet Custom Attribution String

When using the R leaflet package, how can I add something additional to the attribution string (i.e. the 'Leaflet | ...' in the bottom right corner)? For example, I how would I ad

Solution 1:

You can add an attribution argument to addTiles:

leaflet(data = quakes[1:20,]) %>% 
  addTiles(attribution = 'I did this, you hear?! Also Leaflet.') %>%
  addMarkers(~long, ~lat, popup = ~as.character(mag), label = ~as.character(mag))

I'd love to know how to do this with addProviderTiles, though, because that doesn't appear to accept an attribution argument :/

EDIT: okay, my workaround for using provider tiles has been to just use both functions. I hope it's not actually calling both tiles, since that's a bit of a waste of user bandwidth—but hey, it looks fine!

leaflet(data = quakes[1:20,]) %>% 
  addTiles(attribution = 'I did this, you hear?! Also Leaflet.') %>%
  addProviderTiles(providers$OpenStreetMap.Mapnik) %>%
  addMarkers(~long, ~lat, popup = ~as.character(mag), label = ~as.character(mag))

Solution 2:

As @rensa suspects, their second option does indeed embed and fetch both tile sets. However, the setting a blank urlTemplate seems to stop it:

leaflet(data = quakes[1:20,]) %>% 
  addProviderTiles(providers$OpenStreetMap.Mapnik) %>%
  addTiles(urlTemplate = "", attribution = 'I did this, you hear?! Also Leaflet.')

Post a Comment for "R Leaflet Custom Attribution String"