-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.R
97 lines (75 loc) · 2.21 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Dependencies ------------------------------------------------------------
library(shiny)
library(raster)
library(shinycssloaders)
library(shinyjs)
library(tidyverse)
library(readr)
library(lubridate)
library(leaflet)
library(legislatoR)
library(rgdal)
library(sp)
library(stringr)
library(janitor)
library(ggthemes)
library(ggdist)
library(partycoloR)
library(rgeos)
# Constants used throughout code ----------------------------------------
# regex statement to translate constituency name/WKR_NAME to join key
char_to_replace_for_join <- "-|–|[:blank:]|–|[.]"
# Party colors
party_color_map <- list(
CDU = "#000000",
SPD = "#E3001B",
FDP = "#FFEE00",
AfD = "#009EE0",
`BÜNDNIS 90/DIE GRÜNEN` = "#64A12D",
`BÃœNDNIS 90/DIE GRÃœNEN` = "#64A12D",
CSU = "#008AC5",
PDS = "#BE3075",
`DIE LINKE` = "#BE3075",
DP = "#F80000",
none = "#636363"
)
# Register fonts with R, for Windows users
if (.Platform$OS.type == "windows") {
windowsFonts(Corbel=windowsFont("Corbel"))
}
# Party logo path
#party_logo_path <- here::here("test_leaflet_shiny/party_logos")
# Load Scripts ------------------------------------------------------------
# Load SpatialPolygon data for map
source("utils/shapefile_loader.R")
# Load Wahlkreis mapping for each session
source("utils/wahlkreis_data_loader.R")
# Load legislatoR data setup
source("utils/legislator_wrangler.R")
# join shapefiles with legislatoR & constituency data and create popup html
source("utils/shapefile_wrangler.R")
# Load legislatoR theme
source("utils/theme_lgl.R")
# Data Lists to populate dropdown selectors -------------------------------
session_list <- deu_political %>%
distinct(session) %>%
filter(session >= 15) %>%
arrange(session) %>%
pull
names(session_list) <- c(
"BTW 2002 | Session 15",
"BTW 2005 | Session 16",
"BTW 2009 | Session 17",
"BTW 2013 | Session 18",
"BTW 2017 | Session 19"
#"BTW2021 | LP20" # Session 20 not yet in legislatoR data
)
party_list <- deu_political %>%
filter(session >= 15) %>%
distinct(party) %>%
pull
mp_list <- core_de %>%
filter(session >= 15) %>%
distinct(name) %>%
add_row(name = "", .before = 1) %>%
pull