-
Notifications
You must be signed in to change notification settings - Fork 1
/
global.R
322 lines (296 loc) · 10.1 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# Max file size ---------------------------------------------------------------------------------
options(shiny.maxRequestSize = 800 * 1024^2)
# Sanitising error messages (to avoid revealing anything untoward)
options(shiny.sanitize.errors = TRUE)
# Library calls ---------------------------------------------------------------------------------
shhh <- suppressPackageStartupMessages # It's a library, so shhh!
shhh(library(lubridate))
shhh(library(shiny))
shhh(library(janitor))
shhh(library(dplyr))
shhh(library(stringr))
shhh(library(data.table))
shhh(library(shinyjs))
shhh(library(tools))
shhh(library(readr))
shhh(library(testthat))
shhh(library(styler))
shhh(library(tidyr))
shhh(library(ggplot2))
shhh(library(shinyFeedback))
shhh(library(DT))
shhh(library(shinyWidgets))
shhh(library(shinycssloaders))
shhh(library(sparkline))
shhh(library(config))
shhh(library(shinyalert))
shhh(library(shinydisconnect))
shhh(library(praise))
shhh(library(dfeR))
# Following are commented out as they are needed for CI / CD or commit hooks but not for running of app
pigs_will_fly <- FALSE
if (pigs_will_fly == TRUE) {
shhh(library(rsconnect))
shhh(library(git2r))
shhh(library(shinytest2))
shhh(library(diffviewer))
}
# activeTestsInFile ---------------------------------------------------------------------------------
# Extracting the active tests that are run against files
activeTestsInFile <- function(file) {
trimws(gsub("\\(.* # active test", "", grep("(# active test)$", read_lines(file), value = TRUE)))
}
activeTests <- sapply(c("R/fileValidation.r", "R/preCheck1.r", "R/preCheck2.r", "R/mainTests.r"), activeTestsInFile, simplify = FALSE)
numberActiveTests <- length(unlist(activeTests, use.names = FALSE))
# Results boxes ----------------------------------------------------------------------------
pass_results_box <- function() {
div(
div(
class = "panel panel-success",
div(
class = "panel-heading",
style = "color: white;font-size: 18px;font-style: bold;", # background-color: #70ad47;
"All the screener checks passed!"
),
div(
class = "panel-body",
style = "padding-left:27px",
"Your files can now be uploaded to Explore Education Statistics, see our ",
a(href = "https://dfe-analytical-services.github.io/analysts-guide/statistics-production/ees.html", "guidance on using EES", target = "_blank"),
" for more information."
)
)
)
}
fail_results_box <- function(message, table) {
div(
div(
class = "panel panel-danger",
div(
class = "panel-heading",
style = "color: white;font-size: 18px;font-style: bold;", # background-color: #d45859;
textOutput(message)
),
div(
class = "panel-body",
tableOutput(table)
)
)
)
}
advisory_results_box <- function(message, table) {
div(
div(
class = "panel panel-warning",
div(
class = "panel-heading",
style = "color: white;font-size: 18px;font-style: bold; ", # background-color: #e87421;
textOutput(message)
),
div(
class = "panel-body",
tableOutput(table)
)
)
)
}
results_box <- function(message, table) {
div(
div(
class = "panel panel-secondary",
div(
class = "panel-heading",
style = "background-color: #727477; color: white;font-size: 18px; height:47px; vertical-align: middle; line-height:47px; padding-top:0px",
div(
class = "row",
div(
class = "col-sm-9",
textOutput(message)
),
div(
class = "col-sm-3",
downloadButton("download_results", "Download results")
)
)
),
div(
class = "panel-body",
tableOutput(table)
)
)
)
}
ancillary_box <- function() {
div(
div(
class = "panel panel-info",
div(
class = "panel-heading",
style = "color: white;font-size: 18px;font-style: bold;", # background-color: #38a1c1;
"This file should not be uploaded as a standard data file"
),
div(
class = "panel-body",
style = "padding-left:27px",
"The data file only includes geographic levels that are going to be ignored by EES, see our ",
a(href = "https://dfe-analytical-services.github.io/analysts-guide/statistics-production/ees.html#supporting-file-uploads", "guidance on uploading ancillary files", target = "_blank"),
" for more information on how to upload as an ancillary file instead of via the normal data route."
)
)
)
}
info_results_box <- function(message, table) {
div(
div(
class = "panel panel-info",
div(
class = "panel-heading",
style = "color: white;font-size: 18px;font-style: bold; ", # background-color: #e87421;
textOutput(message)
),
div(
class = "panel-body",
tableOutput(table)
)
)
)
}
# summarise_stats ----------------------------------------------------------------------------
# Summarising the counts of the results
summarise_stats <- function(count, text) {
if (count == 1) {
paste0(count, " test ", text)
} else {
paste0(count, " tests ", text)
}
}
# 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;
}
"
# spinner options ---------------------------------------------------------
options(spinner.type = 5)
options(spinner.color = "#c8c8c8") # Grey '#C0C0C0') # Laura's blue #6294C6
options(spinner.size = .5)
# disconnect duck ---------------------------------------------------------
customDisconnectMessage <- function(refresh = "Refresh",
width = 450,
top = 50,
size = 22,
background = "white",
colour = "#ffffff", # "#444444",
overlayColour = "black",
overlayOpacity = 0.6,
refreshColour = "#337ab7") {
checkmate::assert_string(refresh)
checkmate::assert_numeric(size, lower = 0)
checkmate::assert_string(background)
checkmate::assert_string(colour)
checkmate::assert_string(overlayColour)
checkmate::assert_number(overlayOpacity, lower = 0, upper = 1)
checkmate::assert_string(refreshColour)
if (width == "full") {
width <- "100%"
} else if (is.numeric(width) && width >= 0) {
width <- paste0(width, "px")
} else {
stop("disconnectMessage: 'width' must be either an integer, or the string \"full\".", call. = FALSE)
}
if (top == "center") {
top <- "50%"
ytransform <- "-50%"
} else if (is.numeric(top) && top >= 0) {
top <- paste0(top, "px")
ytransform <- "0"
} else {
stop("disconnectMessage: 'top' must be either an integer, or the string \"center\".", call. = FALSE)
}
htmltools::tagList(
htmltools::tags$script(
paste0(
"$(function() {",
" $(document).on('shiny:disconnected', function(event) {",
" $('#custom-disconnect-dialog').show();",
" $('#ss-overlay').show();",
" })",
"});"
)
),
htmltools::tags$div(
id = "custom-disconnect-dialog",
style = "display: none !important;",
htmltools::tags$div(
id = "ss-connect-refresh",
htmltools::tags$p("Something went wrong! Try refreshing the page."),
htmltools::tags$a(id = "ss-reload-link", href = "#", onclick = "window.location.reload(true);")
),
htmltools::tags$div(
id = "ss-connect-image",
style = "display: block !important;",
htmltools::tags$img(id = "ss-reload-image", src = "builder-duck.PNG"),
htmltools::tags$p("If this persists, please contact [email protected] with details of what you were trying to do.")
)
),
htmltools::tags$div(id = "ss-overlay", style = "display: none;"),
htmltools::tags$head(htmltools::tags$style(
glue::glue(
.open = "{{", .close = "}}",
## This hides the old message
"#ss-connect-dialog { display: none !important; }", # rsconnect
"#shiny-disconnected-overlay { display: none !important; }", # local
"#ss-overlay {
background-color: {{overlayColour}} !important;
opacity: {{overlayOpacity}} !important;
position: fixed !important;
top: 0 !important;
left: 0 !important;
bottom: 0 !important;
right: 0 !important;
z-index: 99998 !important;
overflow: hidden !important;
cursor: not-allowed !important;
}",
"#custom-disconnect-dialog {
background: {{background}} !important;
color: {{colour}} !important;
width: {{width}} !important;
transform: translateX(-50%) translateY({{ytransform}}) !important;
font-size: {{size}}px !important;
top: {{top}} !important;
position: fixed !important;
bottom: auto !important;
left: 50% !important;
padding: 0.8em 1.5em !important;
text-align: center !important;
height: auto !important;
opacity: 1 !important;
z-index: 99999 !important;
border-radius: 3px !important;
box-shadow: rgba(0, 0, 0, 0.3) 3px 3px 10px !important;
}",
"#custom-disconnect-dialog a {
display: {{ if (refresh == '') 'none' else 'block' }} !important;
color: {{refreshColour}} !important;
font-size: {{size}}px !important;
margin-top: {{size}}px !important;
font-weight: normal !important;
}",
"#custom-disconnect-dialog a::before {
content: '{{refresh}}';
font-size: {{size}}px;
}"
)
))
)
}