Search code examples
rshinyr-leaflet

Is it posible to close / open legend or overlayGroups/legend from leaflet map R on shiny Server?


I am trying to hide OverlayGroups in R but I don't know how to that. What I am trying to do is to hide it when it is not used. If possible have a button to click it and then It will minimize overlay groups.

Overlay groups

I want to add something like this to hide the Overlaygroups window when it is not used.

Minimize button

My problem is that I want to display my LEAFLET map on small screens from smartphones, so I want to be able to close / open legend and overlay groups when nobody really wants to see them because them occupy lot of useful space for the map.

I want to do something like this, DISPLAY close/open button on legend and overlay groups like on this photo:

REPRODUCIBLE EXAMPLE


Solution

  • In the case of the groups checkbox, leaflet-R already has a way to collapse de groups when nothing is selected. When you add the layers by calling addLayersControl, in the options you can use

    collapsed = TRUE

    addLayersControl(
        baseGroups = c("OSM (default)", "Toner", "Toner Lite"),
        overlayGroups = c("Quakes", "Outline"),
        options = layersControlOptions(collapsed = TRUE)
      )