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
+17 -12
View File
@@ -842,12 +842,7 @@ growth_counties <- reactive({
return(result) return(result)
}) })
output$pop_growth_map <- renderLeaflet({ output$growth_map <- renderLeaflet({
leaflet() %>%
addProviderTiles("Stadia.AlidadeSmooth")
})
output$housing_growth_map <- renderLeaflet({
leaflet() %>% leaflet() %>%
addProviderTiles("Stadia.AlidadeSmooth") addProviderTiles("Stadia.AlidadeSmooth")
}) })
@@ -855,7 +850,8 @@ output$housing_growth_map <- renderLeaflet({
observe({ observe({
req( req(
growth_counties, growth_counties,
input$growth_trend_map_slider input$growth_trend_map_slider,
input$growth_map_metric
) )
growth_year <- input$growth_trend_map_slider growth_year <- input$growth_trend_map_slider
@@ -865,7 +861,8 @@ observe({
year == growth_year year == growth_year
) )
leafletProxy("pop_growth_map", data = growth_county_year) %>% if (input$growth_map_metric == "Population") {
leafletProxy("growth_map", data = growth_county_year) %>%
clearShapes() %>% clearShapes() %>%
addPolygons( addPolygons(
fillColor = "red", fillColor = "red",
@@ -873,8 +870,8 @@ observe({
fillOpacity = ~population_opacity, fillOpacity = ~population_opacity,
weight = 2 weight = 2
) )
} else {
leafletProxy("housing_growth_map", data = growth_county_year) %>% leafletProxy("growth_map", data = growth_county_year) %>%
clearShapes() %>% clearShapes() %>%
addPolygons( addPolygons(
fillColor = "blue", fillColor = "blue",
@@ -882,14 +879,22 @@ observe({
fillOpacity = ~housing_opacity, fillOpacity = ~housing_opacity,
weight = 2 weight = 2
) )
}
}) })
leafletOutput("housing_growth_map", height = "100%") leafletOutput("growth_map", height = "100%")
``` ```
### Map Control {data-height=200} ### Map Control {data-height=200}
```{r} ```{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} Column {data-width=450}