map_shape_click$id as reactive value

I would like to make a shiny app where the coloring of polygons depends on the clicked polygon. I can get it to work when everything is static but using reacitve values kinda trips me up.

Essentially, what I think I have to do is to set the domain argument of the palette and the fill color argument as reactive values.

stgt.counts is my shapefile.

app <- shinyApp(

  ui = bootstrapPage(


  server = function(input, output) { <- reactive({
      paste0("count", input$map_shape_click$id)

    filtered.domain <- reactive({
      paste0("stgt.counts$count", input$map_shape_click$id)

    output$map <- renderLeaflet({ 

      zone <-
      domain <- filtered.domain()
      bins <- c(0,1,2,5,6,7,8)
      pal <- colorBin("YlOrRd", domain = domain, bins = bins)

      m <- leaflet(stgt.counts) %>%

      m %>% addPolygons(
        fillColor = ~pal(zone),
        weight = 2,
        layerID = ~NO,
        opacity = 1, 
        color = "white",
        dashArray = "3",
        fillOpacity = 0.7


    output$text <- renderText({
      if (is.null(input$map_shape_click$id)) return()


The current warning I get is "Warning: Error in cut.default: 'x' must be numeric' - Which I suppose is because zone and domain are strings. Is that right? As this is my first shiny app using reactives I'm guessing there's a much better way to do this. Any help is highly appreciated.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.