title: Custom static coloring for Shiny Leaflet polygons
body: <p>Is there a way to build a custom qualitative color palette that maps category values to color values?</p>
  
  <p>I am trying to build a basic leaflet map in Shiny that colors property parcels (polygons) by their land use (factor). Usually this is simple but I need specific colors for specific categories.</p>
  
  <p>For example, parcels with a land use of 'Commercial' need to be the color '#FF4C4C'. There are about 10 land use categories.</p>
  
  <p>I have tried splitting the data into different layers:</p>
  
  <pre><code>leaflet() %&gt;%
  addPolygons(data=parcels[parcels$category == 'Commercial',], fillColor = '#FF4C4C') %&gt;%
  addPolygons(data=parcels[parcels$category == 'Residential',], fillColor = '#E9E946')
  </code></pre>
  
  <p>And so forth but slicing the large SpatialPolygonsDataFrame ten times is slow and consumes a lot of resources. An added problem is that these categories have sub-categories that will need to be shown later, sometimes up to 20 sub-categories, and slicing the spdf 10+20 times won't do.</p>
  
  <p>All of the documentation and stackoverflow questions I have found focus on defining the ranges between two or more colors, but I don't want ranges. I want an exact mapping between factor levels and specific color codes.</p>
  
  <p>I hope there is a simple answer to this. I was hoping I could do something like:</p>
  
  <pre><code>lu_pal &lt;- c('Residential' = '#E9E946', 'Commercial' = '#FF4C4C')
  </code></pre>
  
  <p>and find a magical function to turn that list into my palette.</p>