title: Dropdown filter in Leaflet for R
body: <p>I have a leaflet map  which I created in R and I would like to add a dropdown filter based on fields in a column. The code looks straightforward in JS, see example here <a href="https://stackoverflow.com/questions/23138767/dropdown-filter-in-leaflet">Leaflet dropdown filter</a>, however I can't figure out how to adjust the code for R.</p>
  
  <pre><code>library(leaflet.extras)
  
  n = c(2, 3, 5) 
  long = c(102.1,102.13,102.2) 
  lat = c(55,55.1,55.15)
  select_cols= c("a","b","c")
   df = data.frame(n, long, lat,select_cols)  
  
  
   pal &lt;- colorFactor(c("navy", "red","green"), domain = c("a","b","c"))
  
  
   leaflet(df)%&gt;% addTiles()%&gt;%
     addCircleMarkers(lng = long,lat=lat,radius= ~n*2,
  color=~pal(select_cols),stroke=F,fillOpacity = 1)
  </code></pre>
  
  <p>Here is the JS code that adds a dropdown filter.</p>
  
  <pre><code>var legend = L.control({position: 'topright'});
  legend.onAdd = function (map) {
  var div = L.DomUtil.create('div', 'info legend');
  div.innerHTML = '&lt;select&gt;&lt;option&gt;1&lt;/option&gt;&lt;option&gt;2&lt;/option&gt;        
  &lt;option&gt;3&lt;/option&gt;&lt;/select&gt;';
  div.firstChild.onmousedown = div.firstChild.ondblclick =         
  L.DomEvent.stopPropagation;
  return div;
  };
  legend.addTo(map);
  </code></pre>
  
  <p>I know how to add the "show hide layers" feature, however I have over 20 different fields and I think it would be easier if the user could select the associated field using a drop down box. </p>