mirror of
https://github.com/dylanbenzi/hurricane_normalization_app.git
synced 2026-07-30 05:08:57 +00:00
remove async
This commit is contained in:
+37
-202
@@ -40,14 +40,6 @@ library(tigris)
|
||||
library(caret)
|
||||
library(scales)
|
||||
library(billboarder)
|
||||
library(mirai)
|
||||
library(promises)
|
||||
library(future)
|
||||
library(crew)
|
||||
|
||||
future::plan(multisession)
|
||||
|
||||
daemons(3, output = T)
|
||||
|
||||
# local testing env setup
|
||||
os <- Sys.info()["sysname"]
|
||||
@@ -76,35 +68,35 @@ config <- config::get(file = paste0(baseDir, "R/dataScripts/restructured/app/con
|
||||
source(file = paste0(baseDir, "R/dataScripts/restructured/app/queries.R"))
|
||||
|
||||
# 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"))
|
||||
#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"))
|
||||
|
||||
# pull static data
|
||||
loss_storms <- get_all_loss_storms()
|
||||
@@ -130,9 +122,9 @@ loading_states <- reactiveValues(
|
||||
)
|
||||
|
||||
onStop(function() {
|
||||
dbDisconnect(con)
|
||||
#dbDisconnect(con)
|
||||
|
||||
daemons(0)
|
||||
#daemons(0)
|
||||
|
||||
#if(!is.null(async_reqs$hurdat_track)) {
|
||||
# tryCatch({
|
||||
@@ -445,176 +437,17 @@ DTOutput("landfalls_table")
|
||||
```
|
||||
|
||||
### Storm Track {data-height=500 .no-padding}
|
||||
```{r eval=FALSE, include=FALSE}
|
||||
task <- ExtendedTask$new(
|
||||
function(...) mirai({
|
||||
get_hurdat_track(storm_selection)
|
||||
}, environment())
|
||||
)
|
||||
|
||||
observeEvent(input$stormSelect, {
|
||||
task$invoke()
|
||||
|
||||
cat("task invoked")
|
||||
})
|
||||
|
||||
observe({
|
||||
req(task$result())
|
||||
|
||||
cat("task result")
|
||||
|
||||
storm_track <- task$result()
|
||||
|
||||
cat("updating map")
|
||||
|
||||
leafletProxy("track_map", data = storm_track) %>%
|
||||
clearShapes() %>%
|
||||
clearMarkers() %>%
|
||||
addPolylines(
|
||||
data = storm_track,
|
||||
lng = ~lon,
|
||||
lat = ~lat,
|
||||
weight = 4,
|
||||
color = "blue"
|
||||
) %>%
|
||||
addCircleMarkers(
|
||||
data = storm_track %>% filter(record_identifier == "L"),
|
||||
lng = ~lon,
|
||||
lat = ~lat,
|
||||
radius = 5,
|
||||
weight = 0,
|
||||
color = "red",
|
||||
fillColor = "red",
|
||||
fillOpacity = 0.8
|
||||
) %>%
|
||||
addCircles(
|
||||
data = storm_track %>% filter(record_identifier == "L"),
|
||||
lng = ~lon,
|
||||
lat = ~lat,
|
||||
radius = ~rmw_meters,
|
||||
weight = 2,
|
||||
color = "red",
|
||||
fillColor = "red",
|
||||
fillOpacity = 0.3
|
||||
)
|
||||
|
||||
track_data(NULL)
|
||||
})
|
||||
|
||||
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}
|
||||
#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)
|
||||
addProviderTiles("CartoDB.Positron", option = providerTileOptions(minZoom = 2, maxZoom = 18))
|
||||
# %>% setView(lng = -89.8, lat = 29.6, zoom = 8)
|
||||
})
|
||||
|
||||
leafletOutput("track_map", height="100%")
|
||||
```
|
||||
|
||||
```{r eval=FALSE, include=FALSE}
|
||||
observe({
|
||||
req(storm_selection$is_selected)
|
||||
|
||||
storm_track <- get_hurdat_track(storm_selection)
|
||||
|
||||
leafletProxy("track_map", data = storm_track) %>%
|
||||
clearShapes() %>%
|
||||
@@ -647,6 +480,8 @@ observe({
|
||||
fillOpacity = 0.3
|
||||
)
|
||||
})
|
||||
|
||||
leafletOutput("track_map", height = "100%")
|
||||
```
|
||||
|
||||
Growth Trends {data-navmenu="Storm Details"}
|
||||
|
||||
@@ -186,9 +186,7 @@ get_hurdat_landfalls <- function(storm) {
|
||||
}
|
||||
|
||||
# returns storm track from HURDAT
|
||||
get_hurdat_track <- function(storm, con = con, hurdat.best_track = hurdat.best_track) {
|
||||
#Sys.sleep(5)
|
||||
|
||||
get_hurdat_track <- function(storm) {
|
||||
query <- hurdat.best_track %>%
|
||||
filter(
|
||||
storm_basin == storm$storm_basin,
|
||||
|
||||
Reference in New Issue
Block a user