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(caret)
|
||||||
library(scales)
|
library(scales)
|
||||||
library(billboarder)
|
library(billboarder)
|
||||||
library(mirai)
|
|
||||||
library(promises)
|
|
||||||
library(future)
|
|
||||||
library(crew)
|
|
||||||
|
|
||||||
future::plan(multisession)
|
|
||||||
|
|
||||||
daemons(3, output = T)
|
|
||||||
|
|
||||||
# local testing env setup
|
# local testing env setup
|
||||||
os <- Sys.info()["sysname"]
|
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"))
|
source(file = paste0(baseDir, "R/dataScripts/restructured/app/queries.R"))
|
||||||
|
|
||||||
# SUPABASE CON
|
# SUPABASE CON
|
||||||
con <- dbConnect(
|
#con <- dbConnect(
|
||||||
RPostgres::Postgres(),
|
# RPostgres::Postgres(),
|
||||||
host = config$db_host,
|
# host = config$db_host,
|
||||||
port = config$db_port,
|
# port = config$db_port,
|
||||||
dbname = config$db_dbname,
|
# dbname = config$db_dbname,
|
||||||
user = config$db_user,
|
# user = config$db_user,
|
||||||
password = config$db_password
|
# password = config$db_password
|
||||||
)
|
#)
|
||||||
|
#
|
||||||
# lazy load DB tables
|
## lazy load DB tables
|
||||||
econ.normalized_landfalls <- tbl(con, I("econ.normalized_landfalls"))
|
#econ.normalized_landfalls <- tbl(con, I("econ.normalized_landfalls"))
|
||||||
econ.storm_base_loss <- tbl(con, I("econ.storm_base_loss"))
|
#econ.storm_base_loss <- tbl(con, I("econ.storm_base_loss"))
|
||||||
econ.usa_yearly <- tbl(con, I("econ.usa_yearly"))
|
#econ.usa_yearly <- tbl(con, I("econ.usa_yearly"))
|
||||||
|
#
|
||||||
fatal.storm_fatalities_type <- tbl(con, I("fatal.storm_fatalities_type"))
|
#fatal.storm_fatalities_type <- tbl(con, I("fatal.storm_fatalities_type"))
|
||||||
fatal.storm_total_fatalities <- tbl(con, I("fatal.storm_total_fatalities"))
|
#fatal.storm_total_fatalities <- tbl(con, I("fatal.storm_total_fatalities"))
|
||||||
|
#
|
||||||
fips.counties <- tbl(con, I("fips.counties"))
|
#fips.counties <- tbl(con, I("fips.counties"))
|
||||||
fips.states <- tbl(con, I("fips.states"))
|
#fips.states <- tbl(con, I("fips.states"))
|
||||||
|
#
|
||||||
gis.affected_area_landfalls <- tbl(con, I("gis.affected_area_landfalls"))
|
#gis.affected_area_landfalls <- tbl(con, I("gis.affected_area_landfalls"))
|
||||||
|
#
|
||||||
hurdat.best_track <- tbl(con, I("hurdat.best_track"))
|
#hurdat.best_track <- tbl(con, I("hurdat.best_track"))
|
||||||
hurdat.hurdat_storms <- tbl(con, I("hurdat.hurdat_storms"))
|
#hurdat.hurdat_storms <- tbl(con, I("hurdat.hurdat_storms"))
|
||||||
|
#
|
||||||
metrics.geo_attributes <- tbl(con, I("metrics.geo_attributes"))
|
#metrics.geo_attributes <- tbl(con, I("metrics.geo_attributes"))
|
||||||
metrics.pop_and_housing <- tbl(con, I("metrics.pop_and_housing"))
|
#metrics.pop_and_housing <- tbl(con, I("metrics.pop_and_housing"))
|
||||||
|
#
|
||||||
public.counties <- tbl(con, I("public.counties"))
|
#public.counties <- tbl(con, I("public.counties"))
|
||||||
|
|
||||||
# pull static data
|
# pull static data
|
||||||
loss_storms <- get_all_loss_storms()
|
loss_storms <- get_all_loss_storms()
|
||||||
@@ -130,9 +122,9 @@ loading_states <- reactiveValues(
|
|||||||
)
|
)
|
||||||
|
|
||||||
onStop(function() {
|
onStop(function() {
|
||||||
dbDisconnect(con)
|
#dbDisconnect(con)
|
||||||
|
|
||||||
daemons(0)
|
#daemons(0)
|
||||||
|
|
||||||
#if(!is.null(async_reqs$hurdat_track)) {
|
#if(!is.null(async_reqs$hurdat_track)) {
|
||||||
# tryCatch({
|
# tryCatch({
|
||||||
@@ -445,177 +437,18 @@ DTOutput("landfalls_table")
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Storm Track {data-height=500 .no-padding}
|
### 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}
|
```{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({
|
output$track_map <- renderLeaflet({
|
||||||
leaflet() %>%
|
leaflet() %>%
|
||||||
addProviderTiles("CartoDB.Positron", option = providerTileOptions(minZoom = 2, maxZoom = 18)) %>%
|
addProviderTiles("CartoDB.Positron", option = providerTileOptions(minZoom = 2, maxZoom = 18))
|
||||||
setView(lng = -80, lat = 32, zoom = 4)
|
# %>% setView(lng = -89.8, lat = 29.6, zoom = 8)
|
||||||
})
|
})
|
||||||
|
|
||||||
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() %>%
|
||||||
clearMarkers() %>%
|
clearMarkers() %>%
|
||||||
@@ -647,6 +480,8 @@ observe({
|
|||||||
fillOpacity = 0.3
|
fillOpacity = 0.3
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
leafletOutput("track_map", height = "100%")
|
||||||
```
|
```
|
||||||
|
|
||||||
Growth Trends {data-navmenu="Storm Details"}
|
Growth Trends {data-navmenu="Storm Details"}
|
||||||
|
|||||||
@@ -186,9 +186,7 @@ get_hurdat_landfalls <- function(storm) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# returns storm track from HURDAT
|
# returns storm track from HURDAT
|
||||||
get_hurdat_track <- function(storm, con = con, hurdat.best_track = hurdat.best_track) {
|
get_hurdat_track <- function(storm) {
|
||||||
#Sys.sleep(5)
|
|
||||||
|
|
||||||
query <- hurdat.best_track %>%
|
query <- hurdat.best_track %>%
|
||||||
filter(
|
filter(
|
||||||
storm_basin == storm$storm_basin,
|
storm_basin == storm$storm_basin,
|
||||||
|
|||||||
Reference in New Issue
Block a user