title: Changing Leaflet map according to input without redrawing
body: <p>I'm wondering how I can change Shiny and Leaflet to plot points according to the change in input without redrawing the whole map.</p>
  <p>The code i'm using is:</p>
  <pre><code>library(leaflet)
  library(shiny)
  library(dplyr)
  library(readr)
  
  ui &lt;- fluidPage(
    titlePanel(&quot;Melbourne Urban Tree Visualisation&quot;),
    leafletOutput(&quot;treedat&quot;),
    uiOutput(&quot;precinct&quot;)
     #Giving an input name and listing out types to choose in the Shiny app
    )
  
  server &lt;- function(input, output){
    
    #td &lt;- read.csv(&quot;treedata.csv&quot;, header = TRUE)
    
    #pal &lt;- colorNumeric(
    #palette = &quot;RdYlGn&quot;,
    #domain = td$LifeExpectencyValue
    #)
    
    output$precinct &lt;- renderUI({
      
      choices &lt;- as.character(unique(td$Precinct))  
      choices &lt;- c('All', choices)
      selectInput(inputId = &quot;precinct&quot;, label = &quot;Precinct&quot;, choices = choices, selected = &quot;CBD&quot;)
      
    })
    
    
    output$treedat &lt;- renderLeaflet({
      #if(is.null(td)) return()
      ## get the choice from teh drop-down box
      PRECINCT = input$precinct
      
      ## supbset the data based on the choice
      if(PRECINCT != 'All'){
        td2 &lt;- td[td$Precinct == PRECINCT, ]
      }else{
        td2 &lt;- td
      }
      ## plot the subsetted ata
      td2 &lt;- leafletProxy(td2) %&gt;% addTiles(
        urlTemplate = 'http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png',
        attribution='Map tiles by &lt;a href=&quot;http://stamen.com&quot;&gt;Stamen Design&lt;/a&gt;, &lt;a href=&quot;http://creativecommons.org/licenses/by/3.0&quot;&gt;CC BY 3.0&lt;/a&gt; &amp;mdash; Map data &amp;copy; &lt;a href=&quot;http://www.openstreetmap.org/copyright&quot;&gt;OpenStreetMap&lt;/a&gt;') %&gt;% 
        addCircleMarkers(radius= 5,
                         fillOpacity = 0.5, 
                         stroke = FALSE,
                         color=~pal(LifeExpectencyValue),
                         popup=paste(&quot;&lt;b&gt;&quot;, td$CommonName,&quot;&lt;/b&gt;&quot;, &quot;&lt;br&gt;&quot;, 
                                     &quot;&lt;b&gt;&quot;,&quot;Years Left:&quot;, &quot;&lt;/b&gt;&quot;, td$LifeExpectency, &quot;&lt;br&gt;&quot;, 
                                     &quot;&lt;b&gt;&quot;,&quot;Genus:&quot;,&quot;&lt;/b&gt;&quot;, td$Genus)) %&gt;% addLegend(pal = pal, 
                                                                        values = ~LifeExpectencyValue, 
                                                                        opacity = 1, 
                                                                        title = &quot;Life Expectency&quot;)
      return(td2)
    })
  }
  
  shinyApp(ui = ui, server = server)
  </code></pre>
  <p>The dataset used for the code is available at this link - <a href="https://data.melbourne.vic.gov.au/Environment/Trees-with-species-and-dimensions-Urban-Forest-/fp38-wiyy" rel="nofollow noreferrer">Melbourne Urban Forest Data</a></p>
  <p>There are a lot of points so I wouldn't want to re-draw each time the input is changed. The input is based on the &quot;Precinct&quot; column in the dataset. Any help here is deeply appreciated.</p>