title: How to make dynamic labels from a spatial polygons dataframe for Polygons on a Leaflet map in R
body: <p>With this script, I am displaying a map with three isochrones. I would like the map to have labels containing the max time represented by each isochrone/polygon.</p>
  
  <p>How should I reference the spatial data frames (iso1/2/3) in the addPolygons() section?</p>
  
  <p>In each of the three addPolygons() bellow I tried a different approach but no luck :( (although the script still works).</p>
  
  <pre><code>library(osrm)
  library(leaflet)
  library(viridisLite)
  
  # Making isochrones
  iso1 = osrmIsochrone(loc = c(9.2,45.5), 
                      breaks = seq(from = 0,
                                   to = 45, 
                                   by = 5),
                      res=75)
  iso2 = osrmIsochrone(loc = c(12.51182,41.92631), 
                       breaks = seq(from = 0,
                                    to = 45, 
                                    by = 15),
                       res=100)
  iso3 = osrmIsochrone(loc = c(11.25581,43.76956), 
                       breaks = seq(from = 0,
                                    to = 45, 
                                    by = 15),
                       res=100)
  
  # colors for leaflet 
  vir = viridis(9)
  
  # palette
  pal1 &lt;- colorNumeric(
    palette = vir,
    domain = iso1@data$id)
  pal2 &lt;- colorNumeric(
    palette = "Blues",
    domain = iso2@data$id)
  pal3 &lt;- colorNumeric(
    palette = "Reds",
    domain = iso3@data$id)
  
  # Plotting interactive map using spdf
  leaflet()%&gt;%
    addTiles("http://mt0.google.com/vt/lyrs=m&amp;hl=en&amp;x={x}&amp;y={y}&amp;z={z}&amp;s=Ga", attribution = 'Google')%&gt;%
    addPolygons(data = iso1,
                fill = TRUE, 
                fillOpacity = 0.7,
                fillColor = ~pal1(id),stroke = FALSE, label = iso1@data$max)%&gt;%
    addPolygons(data = iso2,
                fill = TRUE, 
                fillOpacity = 0.7,
                fillColor = ~pal2(id),stroke = FALSE, label = ~max)%&gt;%
    addPolygons(data = iso3,
                fill = TRUE, 
                fillOpacity = 0.7,
                fillColor = ~pal3(id),stroke = FALSE, label = ~iso3@data$max)
  </code></pre>