title: Add Polygons to R shiny leaflet map
body: <p>How do I add polygons from <a href="http://gadm.org/" rel="noreferrer">Global Administrative areas</a>, so they are clickable.</p>
  
  <p>The simple way describe in the <code>docs</code> that I tried is </p>
  
  <pre><code>adm &lt;- getData('GADM', country='UKR', level=1)
  leaflet() %&gt;% addTiles() %&gt;% addPolygons(data=adm, weight = 3, fillColor = col)
  </code></pre>
  
  <p>But imagine I want a leaflet map that will have onClick actions later.</p>
  
  <p>Based on <a href="https://github.com/rstudio/shiny-examples/blob/master/063-superzip-example/server.R" rel="noreferrer">SuperZip</a>, I need to have something similar to </p>
  
  <pre><code>  map &lt;- createLeafletMap(session, "map")
    session$onFlushed(once=TRUE, function() {
       map$addPolygon(...) 
    })
  </code></pre>
  
  <p>However, there is no addPolygon method and I am confused how will it work for <code>SpartialPolygons</code>. </p>
  
  <p>I also tried converting to <code>geoJSON</code>, similar to <a href="https://ropensci.org/blog/2013/10/23/style-geojson-polygon/" rel="noreferrer">https://ropensci.org/blog/2013/10/23/style-geojson-polygon/</a> or this <a href="https://stackoverflow.com/questions/23546184/add-polygon-to-map-r-leaflet">SO question</a>, but doing</p>
  
  <pre><code>  polys &lt;- fromJSON(&lt;json data file&gt;)
    map &lt;- createLeafletMap(session, "map")
    session$onFlushed(once=TRUE, function() {
      map$geoJson(polys)
    })
  </code></pre>
  
  <p>Gives me an error</p>
  
  <pre><code>Error in func() : attempt to apply non-function
  </code></pre>
  
  <p>Is there a way to do it? Or what am I doing wrong?</p>