title: Using UI to turn on data and leaflet display on and off
body: <p>I have set up a sample of this problem in ui.R and server.R files. This is the ui.R file. There are three random data sets. The one with markers will be displayed no matter what is done with the UI. The other two data sets should get plotted only if requested as "Circles".</p>
  
  <pre><code>library(shiny)
  library(leaflet)
  pageWithSidebar(
      headerPanel("Main Title Here"),
      sidebarPanel(
          checkboxInput('Circles', 'Show Locations', TRUE)
      ),
  
      mainPanel(
          leafletOutput("map")
      )
  
  )
  </code></pre>
  
  <p>The map is generated by server.R, which follows below. This generates the random data and the latitude and longitude locations.</p>
  
  <pre><code>library(shiny)
  library(leaflet)
  library(ggplot2)
  
  shinyServer(function(input, output) {
      output$map &lt;- renderLeaflet({
          leaflet() %&gt;%
               addTiles(group = "OpenStreetMap") %&gt;%
               addMarkers(runif(20,-75,-74),
                    runif(20, 41, 42))
      })
      observe({
          proxy &lt;- leafletProxy("map")
          if (input$Circles == TRUE) {
              proxy %&gt;% addCircles(runif(20,-75,-74),
                             runif(20, 41, 42),
                             group = "Circles",
                             color = "red") %&gt;%
              addCircles(runif(20,-75,-74),
                     runif(20, 41, 42),
                     group = "Circles",
                     color = "blue") %&gt;%
              addLegend(
                  position = "bottomright",
                  colors = c("red", "blue"),
                  labels = c("Group 1", "Group 2")
              )
        # cannot put group or label on legend.
        } else {
            proxy %&gt;% hideGroup("Circles")
            # %&gt;% hideGroup("Group 2")
        }
      })
  })
  </code></pre>
  
  <p>Displaying the circles is turned on (TRUE) as the program starts. I am seeing two major problems here. First, the circles can be turned off, but that is the end of any UI control. The problem is that they cannot be turned on again. If I try starting checkboxInput as FALSE, the UI control will not turn it on. I don't know if that is standard, or if I am doing something wrong.</p>
  
  <p>The second major problem is that I cannot program the legend to be turned off along with the circles. The circles are turned off with the hideGroup() function. This is rejected for use on the legend. I have taken the command I tried and turned it into a comment line. Go ahead and remove the # sign so that you can see the errors that it creates. I have not yet found an alternative.</p>