From d302d2c59dae57303bdf7caa1b9eee7552c0017d Mon Sep 17 00:00:00 2001 From: dylanbenzi Date: Sat, 2 Aug 2025 21:31:53 -0400 Subject: [PATCH] add lfs and lat/lon to calc --- dashboard.Rmd | 166 ++++++++++++++++++++++++++++++++------------------ queries.R | 3 +- 2 files changed, 109 insertions(+), 60 deletions(-) diff --git a/dashboard.Rmd b/dashboard.Rmd index 67f3e96..420221c 100644 --- a/dashboard.Rmd +++ b/dashboard.Rmd @@ -1022,7 +1022,20 @@ Storm Fatalities {data-navmenu="Storm Details"} Normalization Calculator {data-navmenu="Compute"} === -Column {data-width=700 .tabset} +```{r} +# Calculator - Setup Code + +calculator_storm_selection <- reactiveValues( + storm_year = NULL, + storm_name = NULL, + storm_basin = NULL, + full_lf_id = NULL, +) + + +``` + +Column {data-width=700} --- ### Impact Map {.no-padding} @@ -1031,35 +1044,30 @@ Column {data-width=700 .tabset} output$impact_analysis_map <- renderLeaflet({ leaflet() %>% - addProviderTiles("Stadia.AlidadeSmooth") %>% - setView(lng = -80.3, lat = 25.6, zoom = 10) %>% - addCircles( - lng = -80.3, - lat = 25.6, - radius = 37040, - color = "blue", - weight = 2, - opacity = 0.3 - ) %>% - addCircleMarkers( - lng = -80.3, - lat = 25.6, - radius = 5, - weight = 0, - color = "blue", - fillColor = "blue", - fillOpacity = 0.6 - ) + addProviderTiles("Stadia.AlidadeSmooth") #%>% + #setView(lng = -80.3, lat = 25.6, zoom = 10) %>% + #addCircles( + # lng = -80.3, + # lat = 25.6, + # radius = 37040, + # color = "blue", + # weight = 2, + # opacity = 0.3 + #) %>% + #addCircleMarkers( + # lng = -80.3, + # lat = 25.6, + # radius = 5, + # weight = 0, + # color = "blue", + # fillColor = "blue", + # fillOpacity = 0.6 + #) }) leafletOutput("impact_analysis_map", height = "100%") ``` -### Impact Data {.no-padding} -```{r} -# Calculator - Impact Data -``` - Column {data-width=300} --- @@ -1067,18 +1075,7 @@ Column {data-width=300} ```{r} # Calculator - Input # TODO: add data population and compute -#observeEvent(input$stormYear, { -# stormsByChosenYear <- loss_storms[loss_storms$storm_year == input$stormYear, ] -# -# stormsByYear <- loss_storms %>% filter(storm_year == input$stormYear) -# -# updateSelectInput( -# session, -# "stormName", -# choices = stormsByYear$storm_name, -# selected = NULL -# ) -#}) + observeEvent(input$impact_storm_year, { stormsByChosenYear <- all_lf_type_storms[all_lf_type_storms$storm_year == input$impact_storm_year, ] @@ -1092,41 +1089,92 @@ observeEvent(input$impact_storm_year, { ) }) +observeEvent(input$impact_storm_name, { + uniqueLfs <- all_lf_type_storms %>% + filter( + storm_basin == input$impact_storm_basin, + storm_year == input$impact_storm_year, + storm_name == input$impact_storm_name + ) + + updateSelectInput( + session, + "impact_storm_full_lf_id", + choices = uniqueLfs$full_lf_id + ) +}) + +observe({ + req( + input$impact_lat, + input$impact_lon + ) + + new_lat <- as.numeric(input$impact_lat) + new_lon <- as.numeric(input$impact_lon) + + if(new_lat >= -90 & new_lat <= 90 & new_lon >= -180 & new_lon <= 180) { + leafletProxy("impact_analysis_map") %>% + clearShapes() %>% + clearMarkers() %>% + addCircleMarkers( + lng = new_lon, + lat = new_lat, + radius = 2, + weight = 0, + color = "blue", + fillColor = "blue", + fillOpacity = 0.5 + ) %>% + addCircles( + lng = new_lon, + lat = new_lat, + radius = 18000, + weight = 1, + color = "blue", + fillColor = "blue", + fillOpacity = 0.05 + ) + } +}) + div( h6("Storm Selector"), - selectInput( - "impact_storm_basin", - label = NULL, - choices = "AL", - width = "100%" - ), - selectInput( - "impact_storm_year", - label = NULL, - choices = all_lf_type_storms$storm_year, - width = "100%" - ), - selectInput( - "impact_storm_name", - label = NULL, - choices = NULL, - width = "100%" - ), fluidRow( column( 6, selectInput( - "impact_storm_lf_type", + "impact_storm_basin", label = NULL, - choices = "LF", + choices = "AL", width = "100%" - ) + ), ), column( 6, selectInput( - "impact_storm_lf_id", + "impact_storm_year", + label = NULL, + choices = all_lf_type_storms$storm_year, + width = "100%" + ), + ) + ), + fluidRow( + column( + 6, + selectInput( + "impact_storm_name", + label = NULL, + choices = NULL, + width = "100%" + ), + ), + column( + 6, + selectInput( + "impact_storm_full_lf_id", label = NULL, choices = "1", width = "100%" diff --git a/queries.R b/queries.R index 7684f9e..0932b3a 100644 --- a/queries.R +++ b/queries.R @@ -57,6 +57,7 @@ view.all_loss_storms_tracks <- tbl(con, "all_loss_storms_tracks") view.all_conus_landfalls <- tbl(con, "all_conus_landfalls") view.hurdat_ids <- tbl(con, "hurdat_ids") view.all_lf_type_landfalls <- tbl(con, "all_lf_type_landfalls") +view.lf_id_location <- tbl(con, "lf_id_location") #qry <- econ.storm_base_loss %>% # left_join(view.hurdat_track, by = c("storm_basin", "storm_year", "storm_name")) @@ -449,7 +450,7 @@ get_normalized_metric_growth <- function(storm, full_lf_id) { # returns all lf type landfalls get_all_lf_type_landfalls <- function() { - query <- view.all_lf_type_landfalls + query <- view.lf_id_location result <- query %>% collect()