rstudio / flexdashboard

Easy interactive dashboards for R
https://pkgs.rstudio.com/flexdashboard/
Other
816 stars 301 forks source link

reactive leaflet plot not rendering data but only the map #273

Closed SL-itw closed 1 year ago

SL-itw commented 4 years ago

Am I missing something? I am trying to render a plot that when I click on the zipcodes it produces a hchart plot to the side. The problem is the leaflet plot only gives the map but no data however the legend shows the colors. It worked once when I mistakenly rendered it in the side bar but when I try to render it in a row of the body it gives this issue.


metro <- reactive({

  m <- ds_map %>% filter(STATE == input$metro_name)

  return(m)

})

Row

output$map <- renderLeaflet({

   pal <- colorNumeric(viridis(999), NULL)

   map <- leaflet(metro()) %>% 
     addProviderTiles("CartoDB.Positron") %>% 
     clearShapes() %>% 
     addPolygons(stroke = F, 
                 smoothFactor = 0,
                 fillColor = ~pal(ds_map$ses_index), 
                 fillOpacity = 0.7,
                 layerId = ~ds_map$zipcode,
                 label = paste0(ds_map$ses_index)) %>% 
     addLegend(position = "topright", pal = pal, values = ds_map$ses_index, title = "SES Index")

   map

})

##### Click enable function
click_tract <- eventReactive(input$map_shape_click, {
  x <- input$map_shape_click

  y<- x$id

  return(y)

})

observe({

  req(click_tract())

  map <- leafletProxy("map") %>%
    removeShape("htract") %>%
    addPolygons(data = ds_map[ds_map$zipcode == click_tract(), ], 
                fill = F, color = "#FF00FF", opacity = 1, 
                layerId = "htract")

})

tract_data <- reactive({

  return(metro()[metro()$zipcode == click_tract(), ])

})

leafletOutput("map")
Screen Shot 2020-06-30 at 1 29 00 PM
cpsievert commented 3 years ago

Have you tried creating the plot outside of flexdashboard+shiny? A fully reproducible example would help us investigate.

gadenbuie commented 1 year ago

Hi @sl4269! It's been a couple of years and I'm hoping you've figured out the answer to your problem in the mean time. If not, feel free to reply with a reprex and we'll be happy to take another look.