title: Is it possible to update polygon fill in leaflet for shiny without recreating the map object
body: <p>In leaflet, I would normally create a map with:</p>
  
  <p><strong>server.R</strong></p>
  
  <pre><code>shinyServer(function(input, output, session) {
  url &lt;- "custommapboxurl"
  attrib &lt;- "Maps by http://www.mapbox.com/Mapbox"
  
  ...
       map_out &lt;- reactive({
  
          map &lt;- leaflet()%&gt;%
          addTiles(urlTemplate = url, attribution = HTML(attrib))%&gt;%
          addPolygons(data = sub_shape,
                      fill = TRUE,
                      fillColor = colors$color,
                      fillOpacity = .8,
                      stroke = TRUE,
                      weight = 3,
                      color = "white",
                      dashArray = c(5,5),
                      popup = pops
          )
      })
  
      output$myMap &lt;- renderLeaflet({
              map_out()
      })
  ...
  })
  </code></pre>
  
  <p><code>sub_shape</code> above is my shapefile (in this case, zip codes in the US), and colors$color is a dynamic vector of colours that corresponds to each shape. You could recreate with the link here: <a href="http://www.nws.noaa.gov/geodata/catalog/national/html/province.htm" rel="noreferrer">http://www.nws.noaa.gov/geodata/catalog/national/html/province.htm</a>, and <code>colors &lt;- data.frame(color = colorRampPalette(c("white","blue"))(13))</code></p>
  
  <p><strong>ui.R</strong></p>
  
  <pre><code>shinyUI(
      ...
      leafletOutput('myMap', width = "100%" , height = "100%")
      ...
  )
  </code></pre>
  
  <p>This gives:</p>
  
  <p><img src="https://i.stack.imgur.com/NFKpU.png" alt="enter image description here"></p>
  
  <p>What I would like to do is change the vector of colours based on a user's input. For example, they might select a different variable to colour each zip code by, generating a new gradient. </p>
  
  <p>Shiny allows us to do this, as if I change the color vector based on an input widget, the reactive function refreshes, and recreates the map based on the new vector. The problem is that with large shapefile objects, this refresh takes a long time. </p>
  
  <p>Is there any way to change the color of the currently rendered shapes directly, without recreating the entire layer? It seems like the color argument is locked within the leaflet() function. Is there any other way to get at it?</p>