add map controls to switch between housing and pop

This commit is contained in:
2025-10-31 11:23:01 -04:00
parent ce581132c2
commit 16804b72c0
+32 -27
View File
@@ -842,20 +842,16 @@ growth_counties <- reactive({
return(result)
})
output$pop_growth_map <- renderLeaflet({
output$growth_map <- renderLeaflet({
leaflet() %>%
addProviderTiles("Stadia.AlidadeSmooth")
})
output$housing_growth_map <- renderLeaflet({
leaflet() %>%
addProviderTiles("Stadia.AlidadeSmooth")
addProviderTiles("Stadia.AlidadeSmooth")
})
observe({
req(
growth_counties,
input$growth_trend_map_slider
input$growth_trend_map_slider,
input$growth_map_metric
)
growth_year <- input$growth_trend_map_slider
@@ -865,31 +861,40 @@ observe({
year == growth_year
)
leafletProxy("pop_growth_map", data = growth_county_year) %>%
clearShapes() %>%
addPolygons(
fillColor = "red",
color = "red",
fillOpacity = ~population_opacity,
weight = 2
)
leafletProxy("housing_growth_map", data = growth_county_year) %>%
clearShapes() %>%
addPolygons(
fillColor = "blue",
color = "blue",
fillOpacity = ~housing_opacity,
weight = 2
)
if (input$growth_map_metric == "Population") {
leafletProxy("growth_map", data = growth_county_year) %>%
clearShapes() %>%
addPolygons(
fillColor = "red",
color = "red",
fillOpacity = ~population_opacity,
weight = 2
)
} else {
leafletProxy("growth_map", data = growth_county_year) %>%
clearShapes() %>%
addPolygons(
fillColor = "blue",
color = "blue",
fillOpacity = ~housing_opacity,
weight = 2
)
}
})
leafletOutput("housing_growth_map", height = "100%")
leafletOutput("growth_map", height = "100%")
```
### Map Control {data-height=200}
```{r}
radioGroupButtons(
"growth_map_metric",
label = "Display Metric",
choices = c("Population", "Housing"),
selected = "Population",
status = "outline-primary rounded-0",
justified = T
)
```
Column {data-width=450}