-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.R
72 lines (60 loc) · 1.99 KB
/
global.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Global for Carbon-travel-App
library(shiny)
library(bslib)
library(shinylogs)
library(tidyverse)
library(sf)
library(sfnetworks)
library(highcharter)
library(reactable)
library(flowmapblue)
#source(here::here("R", "set_paths.R"))
source(here::here("R", "utils_labels.R"))
source(here::here("R", "utils.R"))
source(here::here("R", "utils_hc.R"))
# Set paths -------------------------------------------------------------
clean_path <- here::here("data", "clean")
# Setup -------------------------------------------------------------------
app_name <- "msf-carbon-app"
app_title <- "MSF Carbon Travel App"
sp_path <- Sys.getenv("SHINYPROXY_PUBLIC_PATH")
is_sp_env <- sp_path != ""
# mapbox api token
if (file.exists(here::here(".Renviron"))) {
readRenviron(here::here(".Renviron"))
}
mbtkn <- Sys.getenv('MAPBOX_ACCESS_TOKEN')
# Import data -------------------------------------------------------------
# Get all travel data
df_travels <- read_rds(here::here(clean_path, "flights", "full_amex_wagram_cwt.rds"))
# Check train for OCP
df_travels %>% filter(org == "OCP",
travel_type == "rail",
emission == 0
) %>% select(
ori_city_name,
dest_city_name,
distance_km,
emission
)
# locations for flowmap
locations <- read_rds(here::here(clean_path,
"cities",
"df_cities.rds")) |>
transmute(id = city_code,
name = city_name,
lat = city_lat,
lon = city_lon)
# date range
init_year <- sort(unique(df_travels$year))
init_date_range <- format(seq.Date(min(df_travels$invoice_date), max(df_travels$invoice_date), by = "month"), "%Y-%m")
min_date <- min(init_date_range)
max_date <- max(init_date_range)
# local disk cache
# shiny::shinyOptions(cache = cachem::cache_disk(here::here(".cache")))
disconnected <- sever::sever_default(
title = "Disconnected",
subtitle = "Sorry your session timed-out or something went wrong",
button = "Reconnect",
button_class = "info"
)