-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.R
84 lines (66 loc) · 2.06 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
#============== Setup ==================
library(shiny)
library(modules)
library(shinydashboard)
library(shinyWidgets)
library(shinyBS)
library(htmltools)
library(highcharter)
options(highcharter.theme = hc_theme_hcrt(tooltip = list(valueDecimals = 2)))
library(apexcharter)
library(stringr)
library(countup)
library(glue)
library(reactable)
library(sparkline)
library(leaflet)
library(dplyr, warn.conflicts = FALSE)
options(dplyr.summarise.inform = FALSE)
library(tidyr)
library(purrr, warn.conflicts = FALSE)
'%!in%' <- function(x,y)!('%in%'(x,y))
#============== Theme ==================
app_title = "Boston Crime"
primary = "#3D88D2"
secondary = "#1D4D7D"
background = "#191919"
text_color <- "#484848"
text_color_light <- "#767676"
text_color_lighter <- "#d7dce1"
bg_color <- "white"
gray <- "#eee"
htmltools::tags$link(href = "https://fonts.googleapis.com/css?family=IBM+Plex+Sans", rel = "stylesheet")
#============== Data ==================
load("data/BostonCrime.RData")
# Read geojson as SF for maps --------
mapdata <- sf::st_read("https://raw.githubusercontent.com/blackmad/neighborhoods/master/boston.geojson") |>
select(name, geometry) |>
rename(neighborhood = "name")
# Crimes of all years --------
crimes <- BostonCrime |>
group_by(neighborhood) |>
count(crime_type) |>
pivot_wider(names_from = crime_type,
values_from = n)
crimes$Crimes <- rowSums(crimes[, 2:9])
# Average crimes between these years --------
crimes_avg <- BostonCrime |>
group_by(neighborhood, year) |>
count(crime_type) |>
filter(crime_type == "violence") |>
pivot_wider(names_from = crime_type,
values_from = n) |>
group_by(neighborhood) |>
summarise(avg_violence = mean(violence, na.rm = TRUE))
# Data for elevated cloropleth --------
mapdata <- mapdata |>
left_join(crimes |> select(1,11),
by = "neighborhood")
#============== Modules ==================
source("modules/drilldown.R")
source("modules/map.R")
source("modules/overview.R")
#============== Utils ==================
source("utils/input.R")
source("utils/metrics_card.R")
source("utils/get_percent.R")