Skip to content

Commit

Permalink
resolve linting notes
Browse files Browse the repository at this point in the history
  • Loading branch information
cjrace committed Jul 19, 2024
1 parent 7cc08af commit f9e2365
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 177 deletions.
13 changes: 4 additions & 9 deletions R/dashboard_panels.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# message("Sourcing dashboard panels")


homepage_panel <- function() {
tabPanel(
"User guide and information",
Expand Down Expand Up @@ -102,26 +99,24 @@ dashboard_panel <- function() {
column(
width = 12,
expandable(
inputId = "details", label = textOutput("dropdown_label"),
input_id = "details", label = textOutput("dropdown_label"),
contents =
div(
id = "div_a",
# class = "well",
# style = "min-height: 100%; height: 100%; overflow-y: visible",
gov_row(
column(
width = 6,
selectizeInput("selectPhase",
"Select a school phase",
choices = choicesPhase
choices = choices_phase
)
),
column(
width = 6,
selectizeInput(
inputId = "selectArea",
label = "Choose an area:",
choices = choicesAreas$area_name
choices = choices_areas$area_name
)
),
column(
Expand Down Expand Up @@ -208,7 +203,7 @@ dashboard_panel <- function() {
width = 12,
selectizeInput("selectBenchLAs",
"Select benchmark local authorities",
choices = choicesLAs$area_name,
choices = choices_las$area_name,
multiple = TRUE,
options = list(maxItems = 3)
)
Expand Down
2 changes: 0 additions & 2 deletions R/dfe_resources.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
# 2023-09-21: update made to change hex codes to AF colours package
# guidance here: https://best-practice-and-impact.github.io/afcolours/

# message("Sourcing gss colour palette")

suppressMessages(
gss_colour_pallette <- afcolours::af_colours("categorical",
colour_format = "hex", n = 6
Expand Down
26 changes: 12 additions & 14 deletions R/dfe_template.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# This file contains scripts which are intended to provide standard styling
# across dashboards. If you want to change anything in this script, please
# talk to the DfE Statistics Development team first.
# talk to the Explore education statistics platforms team first.

# message("Sourcing dfe_template")
valueBox <- function(value, subtitle, icon = NULL,
color = "blue", width = 4,
href = NULL, fontsize = "medium")
# fontsize: can be small, medium or large
{
validateColor(color)
value_box <- function(value, subtitle, icon = NULL,
color = "blue", width = 4,
href = NULL, fontsize = "medium") {
validate_color(color)
if (!is.null(icon)) tagAssert(icon, type = "i")

boxContent <- div(
box_content <- div(
class = paste0("small-box bg-", color),
div(
class = "inner",
Expand All @@ -22,24 +20,24 @@ valueBox <- function(value, subtitle, icon = NULL,
)

if (!is.null(href)) {
boxContent <- a(href = href, boxContent)
box_content <- a(href = href, box_content)
}

div(
class = if (!is.null(width)) paste0("col-sm-", width),
boxContent
box_content
)
}

validColors <- c("blue", "dark-blue", "green", "orange", "purple", "white")
valid_colors <- c("blue", "dark-blue", "green", "orange", "purple", "white")

validateColor <- function(color) {
if (color %in% validColors) {
validate_color <- function(color) {
if (color %in% valid_colors) {
return(TRUE)
}

stop(
"Invalid color: ", color, ". Valid colors are: ",
paste(validColors, collapse = ", "), "."
paste(valid_colors, collapse = ", "), "."
)
}
13 changes: 5 additions & 8 deletions R/plotting.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# message("Sourcing plotting")


createAvgRevTimeSeries <- function(df, inputArea) {
create_avg_rev_timeseries <- function(df, input_area) {
ggplot(df, aes(
x = year,
y = average_revenue_balance,
Expand Down Expand Up @@ -36,13 +33,13 @@ createAvgRevTimeSeries <- function(df, inputArea) {
ylab(str_wrap("Average revenue balance", 16)) +
scale_color_manual(
"Area",
breaks = unique(c("England", inputArea)),
breaks = unique(c("England", input_area)),
values = gss_colour_pallette
)
}

plotAvgRevBenchmark <- function(dfRevenueBalance, inputArea) {
ggplot(dfRevenueBalance, aes(
plot_avg_rev_benchmark <- function(df_revenue_balance, input_area) {
ggplot(df_revenue_balance, aes(
x = str_wrap(area_name, width = 12),
y = average_revenue_balance,
fill = area_name,
Expand Down Expand Up @@ -71,7 +68,7 @@ plotAvgRevBenchmark <- function(dfRevenueBalance, inputArea) {
ylab(str_wrap("Average revenue balance", 12)) +
scale_fill_manual(
"Area",
breaks = unique(dfRevenueBalance$area_name),
breaks = unique(df_revenue_balance$area_name),
values = gss_colour_pallette
)
}
8 changes: 4 additions & 4 deletions R/read_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ read_revenue_data <- function(
file = "data/la_maintained_schools_revenue_reserve_final.csv") {
# This reads in an example file. For the purposes of this demo, we're using
# the latest LA expenditure data downloaded from the EES release.
dfRevenue <- read.csv(file)
df_revenue <- read.csv(file)
# The time period column name has some non-ascii characters so we're just
# going to rename it here.
colnames(dfRevenue)[1] <- "time_period"
dfRevenue <- dfRevenue %>% mutate(
colnames(df_revenue)[1] <- "time_period"
df_revenue <- df_revenue %>% mutate(
year = as.numeric(paste0("20", substr(format(time_period), 5, 6))),
area_name = case_when(
geographic_level == "National" ~ country_name,
geographic_level == "Regional" ~ region_name,
TRUE ~ la_name
)
)
return(dfRevenue)
return(df_revenue)
}
81 changes: 1 addition & 80 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,80 +1 @@
customDisconnectMessage <- function(refresh = "Refresh page",
links = sites_list,
publication_name = ees_pub_name,
publication_link = ees_publication) {
checkmate::assert_string(refresh)
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",
tags$p("You've lost connection to the dashboard server - please try refreshing the page:"),
tags$p(tags$a(
id = "ss-reload-link",
href = "#", "Refresh page",
onclick = "window.location.reload(true);"
)),
if (length(links) > 1) {
tags$p(
"If this persists, you can also view the dashboard at one of our mirror sites:",
tags$p(
tags$a(href = links[1], "Site 1"),
" - ",
tags$a(href = links[2], "Site 2"),
if (length(links) == 3) {
"-"
},
if (length(links) == 3) {
tags$a(href = links[3], "Site 3")
}
)
)
},
if (!is.null(publication_name)) {
tags$p(
"All the data used in this dashboard can also be viewed or
downloaded via the ",
tags$a(
href = publication_link,
publication_name
),
"on Explore Education Statistics."
)
},
tags$p(
"Please contact",
tags$a(
href = "mailto:[email protected]",
"[email protected]"
),
"with details of any problems with this resource."
)
# ),
# htmltools::tags$p("If this persists, you can view tables and data via the ",htmltools::tags$a(href ='https://explore-education-statistics.service.gov.uk/find-statistics/pupil-attendance-in-schools', "Pupil attendance in schools")," release on Explore Education Statistics and 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 = "}}",
"#custom-disconnect-dialog a {
display: {{ if (refresh == '') 'none' else 'inline' }} !important;
color: #1d70b8 !important;
font-size: 16px !important;
font-weight: normal !important;
}"
)
))
)
}
# Add custom functions used across multiple places in the app into this script
24 changes: 12 additions & 12 deletions global.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ sites_list <- c(site_primary, site_overflow)
# publication name (e.g. the EES publication)
ees_pub_name <- "Statistical publication"

# Update with parent publication link
ees_publication <- "https://explore-education-statistics.service.gov.uk/find-statistics/"
# Update with parent publication link, using apprenticeships as an example
ees_publication <- "https://explore-education-statistics.service.gov.uk/find-statistics/apprenticeships"
google_analytics_key <- "Z967JJVQQX"

# Read in the data
Expand All @@ -66,36 +66,36 @@ df_revbal <- read_revenue_data() %>%
))

# Get geographical levels from data
dfAreas <- df_revbal %>%
df_areas <- df_revbal %>%
select(
geographic_level, country_name, country_code,
region_name, region_code,
la_name, old_la_code, new_la_code
) %>%
distinct()

choicesLAs <- dfAreas %>%
choices_las <- df_areas %>%
filter(geographic_level == "Local authority") %>%
select(geographic_level, area_name = la_name) %>%
arrange(area_name)

choicesAreas <- dfAreas %>%
choices_areas <- df_areas %>%
filter(geographic_level == "National") %>%
select(geographic_level, area_name = country_name) %>%
rbind(
dfAreas %>%
df_areas %>%
filter(geographic_level == "Regional") %>%
select(geographic_level, area_name = region_name)
) %>%
rbind(choicesLAs)
rbind(choices_las)

choicesYears <- unique(df_revbal$time_period)
choices_years <- unique(df_revbal$time_period)

choicesPhase <- unique(df_revbal$school_phase)
choices_phase <- unique(df_revbal$school_phase)

expandable <- function(inputId, label, contents) {
govDetails <- shiny::tags$details(
class = "govuk-details", id = inputId,
expandable <- function(input_id, label, contents) {
gov_details <- shiny::tags$details(
class = "govuk-details", id = input_id,
shiny::tags$summary(
class = "govuk-details__summary",
shiny::tags$span(
Expand Down
Loading

0 comments on commit f9e2365

Please sign in to comment.