diff --git a/dashboard.Rmd b/dashboard.Rmd index 047e291..4f2d3a4 100644 --- a/dashboard.Rmd +++ b/dashboard.Rmd @@ -949,65 +949,78 @@ output$test_dy <- renderDygraph({ ``` ### County Data {data-height=450 .no-padding} -```{r} +```{r include=FALSE} # Growth - County Table -great_miami_data <- data.frame( - county_name = c( - "Broward County", - "Collier County", - "Miami-Dade County", - "Monroe County" - ), - housing_1926 = c(3.7, 0, 25, 3.5), - housing_2024 = c(869, 250, 1100, 55), - population_1926 = c(14, 0, 103, 16), - population_2024 = c(2100, 428, 2990, 81) -) -output$great_miami_dt <- renderDT({ +output$county_growth_dt <- renderDT({ + req(growth_counties, input$growth_trend_map_slider, storm_selection$is_selected) + + base_year <- storm_selection$storm_year + current_year <- input$growth_trend_map_slider + + # Get county names + county_names <- public.counties %>% + select(statefp, countyfp, namelsad) %>% + collect() + + county_data <- growth_counties() %>% + st_drop_geometry() %>% + filter(year %in% c(base_year, current_year)) %>% + left_join( + county_names, + by = c("state_fips" = "statefp", "county_fips" = "countyfp") + ) %>% + select(namelsad, year, population, housing_units) %>% + pivot_wider( + names_from = year, + values_from = c(housing_units, population), + names_glue = "{.value}_{year}" + ) + + housing_base <- paste0("housing_units_", base_year) + housing_current <- paste0("housing_units_", current_year) + pop_base <- paste0("population_", base_year) + pop_current <- paste0("population_", current_year) + + county_data <- county_data %>% + select( + namelsad, + all_of(c(housing_base, housing_current, pop_base, pop_current)) + ) + datatable( - great_miami_data, - rownames = F, + county_data, + rownames = FALSE, options = list( order = list(0, 'asc'), - paging = F, - searching = F, - info = F, - lengthChange = F, - server = T + paging = FALSE, + searching = FALSE, + info = FALSE, + lengthChange = FALSE, + server = TRUE ), colnames = c( "County", - "1926 HU", - "2024 HU", - "1926 POP", - "2024 POP" - ), + paste0(base_year, " HU"), + paste0(current_year, " HU"), + paste0(base_year, " POP"), + paste0(current_year, " POP") + ) ) %>% - # Format housing columns with blue background formatStyle( - columns = c("housing_1926", "housing_2024"), - backgroundColor = "rgba(0, 0, 255, 0.2)" + columns = c(housing_base, housing_current), ) %>% - # Format population columns with red background formatStyle( - columns = c("population_1926", "population_2024"), - backgroundColor = "rgba(255, 0, 0, 0.2)" + columns = c(pop_base, pop_current), ) %>% formatCurrency( - columns = c( - "housing_1926", - "housing_2024", - "population_1926", - "population_2024" - ), - currency = "k", + columns = c(housing_base, housing_current, pop_base, pop_current), digits = 0, - before = F + before = FALSE ) }) -DTOutput("great_miami_dt") +DTOutput("county_growth_dt") ``` Normalization Calculator {data-navmenu="Compute"}