title: R Leaflet Shiny : shape_click$id is NULL
body: <p>Based on this example <a href="https://stackoverflow.com/questions/50120572/shiny-r-dynamic-heatmap-with-ggplot-scale-and-speed-issues">here</a>, I wanted to dynamically link the map with a Highchart by simply clicking on the area of interest. However the shape_click funtion returns a $id NULL. I tried it with different shapefile and it doesn't work.
  You'll se below the code from the example adjusted (data available <a href="http://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gpr_000a11a_e.zip" rel="nofollow noreferrer">here</a> to get the $id from the shape_click function.</p>
  
  <pre><code>library(shiny)
  library(dplyr)
  library(leaflet)
  library(sf)
  library(rmapshaper)
  
  ui &lt;- fluidPage(
  
    titlePanel("heatmap"),
  
    # Sidebar with a slider input for year of interest
    sidebarLayout(
      sidebarPanel(
        sliderInput("year",h3("Select year or push play button"),
                    min = 2000, max = 2002, step = 1, value = 2000,
                    animate = TRUE)
      ),
  
      # Output of the map
      mainPanel(
        leafletOutput("unemployment"),
        verbatimTextOutput('summary')
      )
    )
  )
  
  server &lt;- function(input, output) {
    #to get the spacial data: from file in link above
    data.p &lt;- sf::st_read("input/gpr_000a11a_e.shp") %&gt;% 
      st_transform(4326) %&gt;%
      rmapshaper::ms_simplify()
    data.p$PRUID &lt;- as.character(data.p$PRUID) %&gt;% as.numeric
    data.p &lt;- data.p[which(data.p$PRUID &lt; 60),]
  
    lng.center &lt;- -99
    lat.center &lt;- 60
    zoom.def &lt;- 3
  
    #dataframe with same structure as statscan csv after processing
    unem &lt;- runif(10,min=0,max=100)
    unem1 &lt;- unem+runif(1,-10,10)
    unem2 &lt;- unem1+runif(1,-10,10)
    unemployment &lt;- c(unem,unem1,unem2)
    #dataframe with same structure as statscan csv after processing
    X &lt;- data.frame("id" = c(10,11,12,13,24,35,46,47,48,59,
                             10,11,12,13,24,35,46,47,48,59,
                             10,11,12,13,24,35,46,47,48,59),
                    "Unemployment" = unemployment,
                    "year" = c(rep(2000,10),rep(2001,10),rep(2002,10))
    )
  
    data &lt;- left_join(data.p, X, by = c("PRUID"= "id"))
  
    output$unemployment &lt;- renderLeaflet({
      leaflet(data = data.p) %&gt;%
        addProviderTiles("OpenStreetMap.Mapnik", options = providerTileOptions(opacity = 1), group = "Open Street Map") %&gt;%
        setView(lng = lng.center, lat = lat.center, zoom = zoom.def) %&gt;%
        addPolygons(group = 'base', 
                    fillColor = 'transparent', 
                    color = 'black',
                    weight = 1.5)  %&gt;%
        addLegend(pal = pal(), values = X$Unemployment, opacity = 0.7, title = NULL,
                  position = "topright")
    })
  
    get_data &lt;- reactive({
      data[which(data$year == input$year),]
    })
  
    pal &lt;- reactive({
      colorNumeric("viridis", domain = X$Unemployment)
    })
  
    observe({
      data &lt;- get_data()
      leafletProxy('unemployment', data = data) %&gt;%
        clearGroup('polygons') %&gt;%
        addPolygons(group = 'polygons', 
                    fillColor = ~pal()(Unemployment), 
                    fillOpacity = 0.9,
                    color = 'black',
                    weight = 1.5)
    })
    output$summary &lt;- renderPrint({
      event &lt;- input$unemployment_shape_click
      print(event)
    })
  
  }
  
  # Run the application 
  shinyApp(ui = ui, server = server)
  </code></pre>
  
  <p>Thank you </p>