Leaflet/Shiny

82 views
Skip to first unread message

Dennis Chandler

unread,
Dec 10, 2015, 8:33:38 PM12/10/15
to Shiny - Web Framework for R
Hi,

I've been playing with the addLayersControl and would like to know how to detect which layer is selected.  I'm using the various tiles from OpenWeatherMap, but I need the legends. I have them as png files in a folder, but how do I tell shiny which layer is selected so I can throw up the correct legend image?

marco.p...@nispera.com

unread,
Jan 14, 2016, 10:45:15 AM1/14/16
to Shiny - Web Framework for R
I'm having the same problem. Someone can help?
An alternative could be adding the legend directly. It's possible with the original leaflet java library (here), but apparently the R implementation doesn't allow setting this showLegend option.

Here an example:

library(leaflet)

leaflet() %>%
  addProviderTiles("Esri.WorldGrayCanvas") %>%
  addTiles("",group = "none") %>%
  addProviderTiles("OpenWeatherMap.Clouds",group = "Clouds") %>%
  addProviderTiles("OpenWeatherMap.Precipitation",group = "Precipitation") %>%
  addProviderTiles("OpenWeatherMap.PressureContour",group = "Pressure") %>%
  addProviderTiles("OpenWeatherMap.Temperature",group = "Temperature") %>%
  addProviderTiles("OpenWeatherMap.Wind",group = "Wind speed") %>%
  setView(12, 56,zoom = 4) %>%
  addLayersControl(position = "bottomleft",
                   baseGroups = c("none","Clouds","Precipitation", "Pressure","Temperature","Wind speed"),
                   options = layersControlOptions(collapsed = TRUE)) %>%
  hideGroup(c("Clouds","Precipitation", "Pressure","Wind speed","Temperature"))


Reply all
Reply to author
Forward
0 new messages