generated from dfe-analytical-services/shiny-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
global.R
151 lines (125 loc) · 5.15 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# ---------------------------------------------------------
# This is the global file.
# Use it to store functions, library calls, source files etc.
# Moving these out of the server file and into here improves performance
# The global file is run only once when the app launches and stays consistent across users
# whereas the server and UI files are constantly interacting and responsive to user input.
#
# ---------------------------------------------------------
# Library calls ---------------------------------------------------------------------------------
shhh <- suppressPackageStartupMessages # It's a library, so shhh!
shhh(library(tidyverse))
shhh(library(shiny))
shhh(library(shinyjs))
shhh(library(tools))
shhh(library(testthat))
shhh(library(shinytest2))
shhh(library(shinyGovstyle))
shhh(library(shinytitle))
shhh(library(shinyalert))
shhh(library(dplyr))
shhh(library(ggplot2))
shhh(library(plotly))
shhh(library(DT))
shhh(library(htmltools))
shhh(library(formattable))
shhh(library(gt))
shhh(library(janitor))
shhh(library(devtools))
shhh(library(metathis))
shhh(library(checkmate))
shhh(library(DT))
shhh(library(anytime))
shhh(library(R.utils))
shhh(library(R.oo))
shhh(library(dfeshiny))
# devtools::install_github("ewenme/shinya11y")
# shhh(library(shinya11y))
# Functions ---------------------------------------------------------------------------------
# Here's an example function for simplifying the code needed to commas separate numbers:
# cs_num ----------------------------------------------------------------------------
# Comma separating function
cs_num <- function(value) {
format(value, big.mark = ",", trim = TRUE)
}
# tidy_code_function -------------------------------------------------------------------------------
# Code to tidy up the scripts.
tidy_code_function <- function() {
message("----------------------------------------")
message("App scripts")
message("----------------------------------------")
app_scripts <- eval(styler::style_dir(recursive = FALSE)$changed)
message("R scripts")
message("----------------------------------------")
r_scripts <- eval(styler::style_dir("R/")$changed)
message("Test scripts")
message("----------------------------------------")
test_scripts <- eval(styler::style_dir("tests/", filetype = "r")$changed)
script_changes <- c(app_scripts, r_scripts, test_scripts)
return(script_changes)
}
# Source scripts ---------------------------------------------------------------------------------
# Source any scripts here. Scripts may be needed to process data before it gets to the server file.
# It's best to do this here instead of the server file, to improve performance.
# source("R/filename.r")
# appLoadingCSS ----------------------------------------------------------------------------
# Set up loading screen
appLoadingCSS <- "
#loading-content {
position: absolute;
background: #000000;
opacity: 0.9;
z-index: 100;
left: 0;
right: 0;
height: 100%;
text-align: center;
color: #FFFFFF;
}
"
enableBookmarking("url")
site_title <- "DfE FE Outcomes Industry Dashboard"
site_primary <- "https://department-for-education.shinyapps.io/obsm-industry"
sites_list <- c(site_primary) # We can add further mirrors where necessary. Each one can generally handle about 2,500 users simultaneously
ees_pub_name <- "Further education outcome based success measures" # Update this with your parent publication name (e.g. the EES publication)
ees_publication <- "https://explore-education-statistics.service.gov.uk/find-statistics/further-education-outcome-based-success-measures" # Update with parent publication link
google_analytics_key <- "XV00DMHSBX"
source("R/read_data.R")
# Read in data ------------------------------------------------------------
# Read in industry data
dfInd <- read_ind_data() %>%
mutate(NumberSustainedEmployment = suppressWarnings(as.integer(NumberSustainedEmployment))) %>% # Convert columns into numeric values
mutate(IndustrySection = str_to_sentence(IndustrySection)) %>%
# Improve formatting for industry variable
rename(Industry = IndustrySection) %>%
# Manual override to improve formatting
mutate(Ethnicity = ifelse(Ethnicity == "Black/African/Caribbean/Black British", "Black/African/ Caribbean/ Black British", Ethnicity))
# Set up list of choices for input selections -----------------------------
# Get list of all options for SSA Tier 1
choicesSSATier1 <- dfInd %>%
select(SSATier1) %>%
distinct() %>%
arrange(SSATier1 != "All", SSATier1) # Ensure 'All' appears at top of list
# Get list of options for provision type
choicesProvision <- dfInd %>%
select(Provision) %>%
distinct() %>%
arrange(Provision != "All", Provision) # Ensure 'All' appears at top of list
# Get list of options for Industry
choicesIndustry <- dfInd %>%
select(Industry) %>%
distinct() %>%
arrange(Industry != "All", Industry) # Ensure 'All' appears at top of list
expandable <- function(inputId, label, contents) {
govDetails <- shiny::tags$details(
class = "govuk-details", id = inputId,
shiny::tags$summary(
class = "govuk-details__summary",
shiny::tags$span(
class = "govuk-details__summary-text",
label
)
),
shiny::tags$div(contents)
)
}