mirror of
https://github.com/dylanbenzi/hurricane_normalization_app.git
synced 2026-07-30 05:08:57 +00:00
update local dev testing env
This commit is contained in:
+146
-41
@@ -42,13 +42,34 @@ library(scales)
|
|||||||
library(billboarder)
|
library(billboarder)
|
||||||
library(mirai)
|
library(mirai)
|
||||||
library(promises)
|
library(promises)
|
||||||
|
library(future)
|
||||||
|
library(crew)
|
||||||
|
|
||||||
daemons(3)
|
future::plan(multisession)
|
||||||
|
|
||||||
|
daemons(3, output = T)
|
||||||
|
|
||||||
|
# local testing env setup
|
||||||
|
os <- Sys.info()["sysname"]
|
||||||
|
|
||||||
linuxdir <- "/home/dylan/Personal/Projects/Hurricane Normalization/"
|
linuxdir <- "/home/dylan/Personal/Projects/Hurricane Normalization/"
|
||||||
macdir <- "~/Desktop/Personal/Projects/Hurricane Normalization/"
|
macdir <- "~/Desktop/Personal/Projects/Hurricane Normalization/"
|
||||||
#baseDir <- macdir
|
widir <- "E/..."
|
||||||
baseDir <- linuxdir
|
|
||||||
|
if(!is.null(os)) {
|
||||||
|
if(grepl("darwin", os, ignore.case = T)) {
|
||||||
|
cat("OS: Mac")
|
||||||
|
baseDir <- macdir
|
||||||
|
} else if(grepl("linux", os, ignore.case = T)) {
|
||||||
|
cat("OS: Linux")
|
||||||
|
baseDir <- linuxdir
|
||||||
|
} else if(grepl("windows", os, ignore.case = T)) {
|
||||||
|
cat("OS: Win")
|
||||||
|
baseDir <- windir
|
||||||
|
} else {
|
||||||
|
cat("Cannot identify OS")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
config <- config::get(file = paste0(baseDir, "R/dataScripts/restructured/app/config.yml"))
|
config <- config::get(file = paste0(baseDir, "R/dataScripts/restructured/app/config.yml"))
|
||||||
|
|
||||||
@@ -330,6 +351,13 @@ Col {data-width=500}
|
|||||||
HTML('
|
HTML('
|
||||||
|
|
||||||
')
|
')
|
||||||
|
|
||||||
|
textOutput("current_time")
|
||||||
|
|
||||||
|
output$current_time <- renderText({
|
||||||
|
invalidateLater(100)
|
||||||
|
format(Sys.time(), "%H:%M:%S %p")
|
||||||
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
### Normalization Cost Index {data-height=800}
|
### Normalization Cost Index {data-height=800}
|
||||||
@@ -418,40 +446,24 @@ DTOutput("landfalls_table")
|
|||||||
|
|
||||||
### Storm Track {data-height=500 .no-padding}
|
### Storm Track {data-height=500 .no-padding}
|
||||||
```{r eval=FALSE, include=FALSE}
|
```{r eval=FALSE, include=FALSE}
|
||||||
track_data <- reactiveVal(NULL)
|
task <- ExtendedTask$new(
|
||||||
mirai_job <- reactiveVal(NULL)
|
function(...) mirai({
|
||||||
|
get_hurdat_track(storm_selection)
|
||||||
|
}, environment())
|
||||||
|
)
|
||||||
|
|
||||||
observe({
|
observeEvent(input$stormSelect, {
|
||||||
req(storm_selection$is_selected)
|
task$invoke()
|
||||||
|
|
||||||
storm <- reactiveValuesToList(storm_selection)
|
cat("task invoked")
|
||||||
|
|
||||||
cat("starting qry for storm track")
|
|
||||||
|
|
||||||
m <- async_db_query(get_hurdat_track, storm)
|
|
||||||
|
|
||||||
mirai_job(m)
|
|
||||||
|
|
||||||
track_data(NULL)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
observe({
|
observe({
|
||||||
req(mirai_job())
|
req(task$result())
|
||||||
|
|
||||||
if(!unresolved(mirai_job())) {
|
cat("task result")
|
||||||
result <- mirai_job()$data
|
|
||||||
|
|
||||||
track_data(result)
|
|
||||||
mirai_job(NULL)
|
|
||||||
} else {
|
|
||||||
invalidateLater(100)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
observe({
|
|
||||||
req(track_data())
|
|
||||||
|
|
||||||
storm_track <- track_data()
|
storm_track <- task$result()
|
||||||
|
|
||||||
cat("updating map")
|
cat("updating map")
|
||||||
|
|
||||||
@@ -499,10 +511,110 @@ leafletOutput("track_map", height="100%")
|
|||||||
```
|
```
|
||||||
|
|
||||||
```{r}
|
```{r}
|
||||||
|
#a <- reactiveVal(NULL)
|
||||||
|
|
||||||
|
observe({
|
||||||
|
req(storm_selection, storm_selection$is_selected)
|
||||||
|
|
||||||
|
storm_basin <- storm_selection$storm_basin
|
||||||
|
storm_name <- storm_selection$storm_name
|
||||||
|
storm_year <- storm_selection$storm_year
|
||||||
|
|
||||||
|
mirai({
|
||||||
|
library(tidyverse)
|
||||||
|
library(dplyr)
|
||||||
|
library(DBI)
|
||||||
|
|
||||||
|
Sys.sleep(5)
|
||||||
|
|
||||||
|
linuxdir <- "/home/dylan/Personal/Projects/Hurricane Normalization/"
|
||||||
|
macdir <- "~/Desktop/Personal/Projects/Hurricane Normalization/"
|
||||||
|
#baseDir <- macdir
|
||||||
|
baseDir <- linuxdir
|
||||||
|
|
||||||
|
config <- config::get(file = paste0(baseDir, "R/dataScripts/restructured/app/config.yml"))
|
||||||
|
|
||||||
|
# SUPABASE CON
|
||||||
|
con <- dbConnect(
|
||||||
|
RPostgres::Postgres(),
|
||||||
|
host = config$db_host,
|
||||||
|
port = config$db_port,
|
||||||
|
dbname = config$db_dbname,
|
||||||
|
user = config$db_user,
|
||||||
|
password = config$db_password
|
||||||
|
)
|
||||||
|
|
||||||
|
# lazy load DB tables
|
||||||
|
|
||||||
|
econ.normalized_landfalls <- tbl(con, I("econ.normalized_landfalls"))
|
||||||
|
econ.storm_base_loss <- tbl(con, I("econ.storm_base_loss"))
|
||||||
|
econ.usa_yearly <- tbl(con, I("econ.usa_yearly"))
|
||||||
|
|
||||||
|
fatal.storm_fatalities_type <- tbl(con, I("fatal.storm_fatalities_type"))
|
||||||
|
fatal.storm_total_fatalities <- tbl(con, I("fatal.storm_total_fatalities"))
|
||||||
|
|
||||||
|
fips.counties <- tbl(con, I("fips.counties"))
|
||||||
|
fips.states <- tbl(con, I("fips.states"))
|
||||||
|
|
||||||
|
gis.affected_area_landfalls <- tbl(con, I("gis.affected_area_landfalls"))
|
||||||
|
|
||||||
|
hurdat.best_track <- tbl(con, I("hurdat.best_track"))
|
||||||
|
hurdat.hurdat_storms <- tbl(con, I("hurdat.hurdat_storms"))
|
||||||
|
|
||||||
|
metrics.geo_attributes <- tbl(con, I("metrics.geo_attributes"))
|
||||||
|
metrics.pop_and_housing <- tbl(con, I("metrics.pop_and_housing"))
|
||||||
|
|
||||||
|
public.counties <- tbl(con, I("public.counties"))
|
||||||
|
|
||||||
|
track_data <- hurdat.best_track %>%
|
||||||
|
filter(
|
||||||
|
storm_basin == !!storm_basin,
|
||||||
|
storm_year == !!storm_year,
|
||||||
|
storm_name == !!storm_name
|
||||||
|
) %>%
|
||||||
|
mutate(
|
||||||
|
lon = sql("ST_X(ST_Transform(location::geometry, 4326))"),
|
||||||
|
lat = sql("ST_Y(ST_Transform(location::geometry, 4326))"),
|
||||||
|
rmw_meters = (rmw * 1852) # convert nautical miles to meters
|
||||||
|
) %>%
|
||||||
|
select(
|
||||||
|
datetime,
|
||||||
|
lon,
|
||||||
|
lat,
|
||||||
|
rmw,
|
||||||
|
record_identifier,
|
||||||
|
rmw_meters
|
||||||
|
) %>% collect()
|
||||||
|
|
||||||
|
dbDisconnect(con)
|
||||||
|
|
||||||
|
track_data
|
||||||
|
}, storm_basin = storm_basin, storm_name = storm_name, storm_year = storm_year) %...>% (function(track_data) {
|
||||||
|
leafletProxy("track_map") %>%
|
||||||
|
clearShapes() %>%
|
||||||
|
clearMarkers() %>%
|
||||||
|
addPolylines(
|
||||||
|
data = track_data,
|
||||||
|
lng = ~lon,
|
||||||
|
lat = ~lat,
|
||||||
|
weight = 4,
|
||||||
|
color = "blue"
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
output$track_map <- renderLeaflet({
|
||||||
|
leaflet() %>%
|
||||||
|
addProviderTiles("CartoDB.Positron", option = providerTileOptions(minZoom = 2, maxZoom = 18)) %>%
|
||||||
|
setView(lng = -80, lat = 32, zoom = 4)
|
||||||
|
})
|
||||||
|
|
||||||
|
leafletOutput("track_map", height="100%")
|
||||||
|
```
|
||||||
|
|
||||||
|
```{r eval=FALSE, include=FALSE}
|
||||||
observe({
|
observe({
|
||||||
req(storm_selection$is_selected)
|
req(storm_selection$is_selected)
|
||||||
|
|
||||||
storm_track <- get_hurdat_track(storm_selection)
|
|
||||||
|
|
||||||
leafletProxy("track_map", data = storm_track) %>%
|
leafletProxy("track_map", data = storm_track) %>%
|
||||||
clearShapes() %>%
|
clearShapes() %>%
|
||||||
@@ -535,15 +647,8 @@ observe({
|
|||||||
fillOpacity = 0.3
|
fillOpacity = 0.3
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
output$track_map <- renderLeaflet({
|
|
||||||
leaflet() %>%
|
|
||||||
addProviderTiles("CartoDB.Positron", option = providerTileOptions(minZoom = 2, maxZoom = 18)) %>%
|
|
||||||
setView(lng = -80, lat = 32, zoom = 4)
|
|
||||||
})
|
|
||||||
|
|
||||||
leafletOutput("track_map", height="100%")
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Growth Trends {data-navmenu="Storm Details"}
|
Growth Trends {data-navmenu="Storm Details"}
|
||||||
================================
|
================================
|
||||||
|
|
||||||
@@ -617,7 +722,7 @@ katrina_counties <- reactive({
|
|||||||
counties <- get_normalized_metric_growth(test_storm, "LF2")
|
counties <- get_normalized_metric_growth(test_storm, "LF2")
|
||||||
|
|
||||||
result <- counties %>%
|
result <- counties %>%
|
||||||
filter(year == 2006) %>%
|
filter(year == 2024) %>%
|
||||||
mutate(
|
mutate(
|
||||||
population_opacity = rescale(normalized_population, to = c(0.2, 0.8), from = range(normalized_population, na.rm = T)),
|
population_opacity = rescale(normalized_population, to = c(0.2, 0.8), from = range(normalized_population, na.rm = T)),
|
||||||
housing_opacity = rescale(normalized_housing, to = c(0.2, 0.8), from = range(normalized_housing, na.rm = T))
|
housing_opacity = rescale(normalized_housing, to = c(0.2, 0.8), from = range(normalized_housing, na.rm = T))
|
||||||
|
|||||||
Reference in New Issue
Block a user