title: Adding multiple layers to leaflet map in Shiny in R
body: <p>I am having trouble adding different layers in my shiny app. I want to add a group of polygons along with a group of circle markers along with a group of arbitrary (.png) icons. I have the group of geojson files that are added in a for loop that is wrapped in an observe({}) statement with the function 
  map$addGeoJSON(x) where x is a feature with coordinates. The 'map' object is created by the command</p>
  
  <pre><code>map &lt;- createLeafletMap(session, 'map')
  </code></pre>
  
  <p>This is all fine and dandy, and the polygons get added fine. I also want to commit to this way of adding the polygons. That should not have to change.</p>
  
  <p>The error happens when I try to add markers onto that map object in the same way (e.g. with map$addMarkers(....) ) Below is the error and the code for the app that tries to add markers in the desired way and fails.
  The shiny app below with the quakes data recreates my error</p>
  
  <pre><code>"Listening on ...
  Warning: Error in observerFunc: attempt to apply non-function
  Stack trace (innermost first):
      56: observerFunc [C:/Users/jbz/Desktop/leaflet-map-question.R#35]
       1: runApp
  ERROR: [on_request_read] connection reset by peer"
  
  library(shiny)
  library(leaflet)
  library(RColorBrewer)
  
  ui &lt;- bootstrapPage(
    tags$style(type = "text/css", "html, body {width:100%;height:100%}"),
    leafletMap("map", width = "100%", height = "100%",
               options=list(center = c(40.736, -73.99), zoom = 14)),
    absolutePanel(top = 10, right = 10,
                  sliderInput("range", "Magnitudes", min(quakes$mag), max(quakes$mag),
                              value = range(quakes$mag), step = 0.1
                  ),
                  selectInput("colors", "Color Scheme",
                              rownames(subset(brewer.pal.info, category %in% c("seq", "div")))
                  ),
                  checkboxInput("legend", "Show legend", TRUE)
    )
  )
  
  server &lt;- function(input, output, session) {
  
    filteredData &lt;- reactive({
      quakes[quakes$mag &gt;= input$range[1] &amp; quakes$mag &lt;= input$range[2],]
    })
  
    colorpal &lt;- reactive({
      colorNumeric(input$colors, quakes$mag)
    })
  
  
    map &lt;- createLeafletMap(session, 'map')
  
    observe({
      df &lt;- filteredData()
      map$addMarkers(
        lng=df$Lon, lat=df$Lat, popup = paste(as.character(df$mag)))
    })
  }
  
  shinyApp(ui, server)
  </code></pre>
  
  <p>(How) can I add markers correctly while insisting on using the function createLeafletMap()?</p>
  
  <pre><code>map &lt;- createLeafletMap(session, 'map')
  </code></pre>