From b69812942c2ca8721c04f09b6a8c76df16933e8b Mon Sep 17 00:00:00 2001 From: dylanbenzi Date: Tue, 7 Apr 2026 22:25:40 -0400 Subject: [PATCH] modify file formatting --- app/queries.R | 1 - app/server.R | 127 ++++++++++++++++++++++++-------------------------- app/ui.R | 1 - 3 files changed, 62 insertions(+), 67 deletions(-) diff --git a/app/queries.R b/app/queries.R index 22bba9d..b548d88 100644 --- a/app/queries.R +++ b/app/queries.R @@ -546,4 +546,3 @@ get_county_and_state <- function(df) { return(result) } - diff --git a/app/server.R b/app/server.R index e83b000..6cf6fcf 100644 --- a/app/server.R +++ b/app/server.R @@ -135,6 +135,13 @@ server <- function(input, output, session) { choices = unique_lfs$full_lf_id, selected = unique_lfs$full_lf_id[1] ) + + updateSliderInput( + session, + "growth_trend_map_slider", + min = storm_selection$storm_year, + value = storm_selection$storm_year + ) }) observeEvent(input$load_storm, { @@ -304,12 +311,7 @@ server <- function(input, output, session) { arrange(datetime) return(result) - }) %>% - bindCache( - storm_selection$storm_year, - storm_selection$storm_name, - storm_selection$storm_basin - ) + }) output$track_map <- renderLeaflet({ track_data <- storm_track() @@ -534,26 +536,26 @@ server <- function(input, output, session) { ) g <- dygraph(track_xts) %>% - dyAxis("y", label = "Windspeed (kt)") %>% + dyAxis("y", label = "Windspeed (kt)") %>% dyAxis("y2", label = "Pressure (mb)", independentTicks = TRUE) %>% - dySeries("Windspeed", axis = "y", color = "#4dabf7") %>% - dySeries("Pressure", axis = "y2", color = "#f03e3e") %>% + dySeries("Windspeed", axis = "y", color = "#4dabf7") %>% + dySeries("Pressure", axis = "y2", color = "#f03e3e") %>% dyOptions(drawGrid = FALSE) %>% dyLegend(show = "always") - Reduce(function(g, i) { - g %>% dyShading( - from = track_data$datetime[i], - to = track_data$datetime[i + 1], - color = paste0(track_data$line_color[i], "33") - ) - }, seq_len(nrow(track_data) - 1), init = g) - }) %>% - bindCache( - storm_selection$storm_year, - storm_selection$storm_name, - storm_selection$storm_basin + Reduce( + function(g, i) { + g %>% + dyShading( + from = track_data$datetime[i], + to = track_data$datetime[i + 1], + color = paste0(track_data$line_color[i], "33") + ) + }, + seq_len(nrow(track_data) - 1), + init = g ) + }) storm_yearly_normalization <- reactive({ req( @@ -565,12 +567,7 @@ server <- function(input, output, session) { result <- get_all_normalized_cost_index(storm_selection) return(result) - }) %>% - bindCache( - storm_selection$storm_year, - storm_selection$storm_name, - storm_selection$storm_basin - ) + }) output$cost_index_chart <- renderDygraph({ req( @@ -648,30 +645,6 @@ server <- function(input, output, session) { dyAxis("x", drawGrid = F) %>% dyLegend(show = "always", width = 400, hideOnMouseOut = FALSE) %>% dyRangeSelector() - }) %>% - bindCache( - storm_selection$storm_year, - storm_selection$storm_name, - storm_selection$storm_basin, - input$storm_overview_cost_index_lf_select, - input$storm_overview_cost_index_mmh_mmp, - input$storm_overview_cost_index_scale, - input$storm_overview_cost_index_y_scale - ) - - observe({ - req( - storm_selection$storm_basin, - storm_selection$storm_year, - storm_selection$storm_name - ) - - updateSliderInput( - session, - "growth_trend_map_slider", - min = storm_selection$storm_year, - value = storm_selection$storm_year - ) }) growth_counties <- reactive({ @@ -703,33 +676,57 @@ server <- function(input, output, session) { st_as_sf(wkt = "geom_wkt") return(result) - }) %>% - bindCache( - storm_selection$storm_year, - storm_selection$storm_name, - storm_selection$storm_basin, - input$growth_trend_lf_select - ) - - output$growth_map <- renderLeaflet({ - leaflet() %>% - addProviderTiles("Stadia.AlidadeSmooth") }) - observe({ - req(growth_counties()) + output$growth_map <- renderLeaflet({ + req( + growth_counties(), + input$growth_trend_map_slider, + input$growth_map_metric + ) counties_data <- growth_counties() combined_geom <- st_union(counties_data) growth_bbox <- st_bbox(combined_geom) - leafletProxy("growth_map") %>% + growth_year <- input$growth_trend_map_slider + growth_county_year <- counties_data %>% + filter(year == growth_year) + + map <- leaflet() %>% + addProviderTiles("Stadia.AlidadeSmooth") %>% fitBounds( lng1 = growth_bbox[["xmin"]], lng2 = growth_bbox[["xmax"]], lat1 = growth_bbox[["ymin"]], lat2 = growth_bbox[["ymax"]] ) + + if (input$growth_map_metric == "Population") { + map <- map %>% + addPolygons( + data = growth_county_year, + group = "counties", + fillColor = "red", + color = "red", + fillOpacity = ~population_opacity, + weight = 1, + popup = ~name + ) + } else { + map <- map %>% + addPolygons( + data = growth_county_year, + group = "counties", + fillColor = "blue", + color = "blue", + fillOpacity = ~housing_opacity, + weight = 1, + popup = ~name + ) + } + + return(map) }) observe({ diff --git a/app/ui.R b/app/ui.R index 1335202..7215902 100644 --- a/app/ui.R +++ b/app/ui.R @@ -147,7 +147,6 @@ ui <- page_navbar( ) ) ), - nav_panel("Meterology"), nav_panel( "Cost Normalization", layout_columns(