Skip to content

Commit

Permalink
tidying global file
Browse files Browse the repository at this point in the history
  • Loading branch information
cjrace committed Jul 20, 2024
1 parent 992aa4d commit 9a3a648
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 151 deletions.
Empty file added R/dashboard_variables.R
Empty file.
14 changes: 0 additions & 14 deletions R/dfe_resources.R

This file was deleted.

10 changes: 10 additions & 0 deletions R/dfe_template.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@ validate_color <- function(color) {
paste(valid_colors, collapse = ", "), "."
)
}

# Current GSS colours for use in charts. These are taken from the current
# guidance here:
# https://analysisfunction.civilservice.gov.uk/policy-store/data-visualisation-colours-in-charts/
# Note the advice on trying to keep to a maximum of 4 series in a single plot
# AF colours package guidance here: https://best-practice-and-impact.github.io/afcolours/

suppressMessages(
gss_colour_pallette <- afcolours::af_colours("categorical", colour_format = "hex", n = 4)
)
89 changes: 2 additions & 87 deletions R/dashboard_panels.R → R/ui_panels/example_tab_1.R
Original file line number Diff line number Diff line change
@@ -1,91 +1,6 @@
homepage_panel <- function() {
example_tab_1_panel <- function() {
tabPanel(
"User guide and information",
gov_main_layout(
gov_row(
column(
12,
h1("Department for Education (DfE) Analytical Services R-Shiny data dashboard template"),
br(),
br()
),

## Left panel -------------------------------------------------------

column(
6,
div(
div(
class = "panel panel-info",
div(
class = "panel-heading",
style = "color: white;font-size: 18px;font-style: bold;
background-color: #1d70b8;",
h2("Contents")
),
div(
class = "panel-body",
tags$div(
h3("Introduction"),
p("This app demonstrates the DfE Analytical Services R-Shiny
data dashboard template."),
p("You might want to add some brief introductory text here
alongside some links to different tabs within your
dashboard. Here's an example of a link working:"),
p(actionLink("link_to_app_content_tab", "Dashboard panel")),
p("You need to add an observeEvent() function to the server.R
script for any link that navigates within your App.")
),
br()
)
)
),
),

## Right panel ------------------------------------------------------

column(
6,
div(
div(
class = "panel panel-info",
div(
class = "panel-heading",
style = "color: white;font-size: 18px;font-style: bold;
background-color: #1d70b8;",
h2("Background Info")
),
div(
class = "panel-body",
h3("Context and purpose"),
p("This app is the DfE Analytical Service's R-Shiny template
demonstration app and is being developed to provide a coherent
styling for DfE dashboards alongside some useful example
componenets that teams can adapt for their own uses."),
p("DfE teams using this template should avoid changing the
styling and layout, keeping the header, footer and side
navigation list formats."),
p("You might want to add some relevant background information
for your users here. For example some useful links to your
Explore Education Statistics (EES)
publication, data sources and other relevant resources."),
h3("Guidance sources"),
p("For example, here we'll add some of the key resources we draw
on to guide styling and vizualisation...")
)
)
)
)
)
)
)
}


dashboard_panel <- function() {
tabPanel(
value = "dashboard",
"Dashboard",
"Example tab 1",

# Define UI for application that draws a histogram

Expand Down
82 changes: 82 additions & 0 deletions R/ui_panels/user_guide.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
user_guide_panel <- function() {
tabPanel(
"User guide",
gov_main_layout(
gov_row(
column(
12,
h1("Department for Education (DfE) Analytical Services R-Shiny data dashboard template"),
br(),
br()
),

## Left panel -------------------------------------------------------

column(
6,
div(
div(
class = "panel panel-info",
div(
class = "panel-heading",
style = "color: white;font-size: 18px;font-style: bold;
background-color: #1d70b8;",
h2("Contents")
),
div(
class = "panel-body",
tags$div(
h3("Introduction"),
p("This app demonstrates the DfE Analytical Services R-Shiny
data dashboard template."),
p("You might want to add some brief introductory text here
alongside some links to different tabs within your
dashboard. Here's an example of a link working:"),
p(actionLink("link_to_app_content_tab", "Example tab 1")),
p("You need to add an observeEvent() function to the server.R
script for any link that navigates within your App.")
),
br()
)
)
),
),

## Right panel ------------------------------------------------------

column(
6,
div(
div(
class = "panel panel-info",
div(
class = "panel-heading",
style = "color: white;font-size: 18px;font-style: bold;
background-color: #1d70b8;",
h2("Background Info")
),
div(
class = "panel-body",
h3("Context and purpose"),
p("This app is the DfE Analytical Service's R-Shiny template
demonstration app and is being developed to provide a coherent
styling for DfE dashboards alongside some useful example
componenets that teams can adapt for their own uses."),
p("DfE teams using this template should avoid changing the
styling and layout, keeping the header, footer and side
navigation list formats."),
p("You might want to add some relevant background information
for your users here. For example some useful links to your
Explore Education Statistics (EES)
publication, data sources and other relevant resources."),
h3("Guidance sources"),
p("For example, here we'll add some of the key resources we draw
on to guide styling and vizualisation...")
)
)
)
)
)
)
)
}
14 changes: 14 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
# Add custom functions used across multiple places in the app into this script

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(
class = "govuk-details__summary-text",
label
)
),
shiny::tags$div(contents)
)
}
95 changes: 55 additions & 40 deletions global.R
Original file line number Diff line number Diff line change
@@ -1,64 +1,94 @@
# -----------------------------------------------------------------------------
# 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
#
# Moving these out of the server file and into here improves performance as 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!

# Core shiny and R packages
shhh(library(shiny))
shhh(library(bslib))
shhh(library(rstudioapi))

# Custom packages
shhh(library(dfeR))
shhh(library(dfeshiny))
shhh(library(shinyGovstyle))

# Creating charts and tables
shhh(library(ggplot2))
shhh(library(DT))

# Data and string manipulation
shhh(library(dplyr))
shhh(library(stringr))
shhh(library(ggiraph))

# Shiny extensions
shhh(library(shinyjs))
shhh(library(tools))
shhh(library(testthat))
shhh(library(stringr))
shhh(library(shinydashboard))
shhh(library(shinyWidgets))
shhh(library(shinyGovstyle))
shhh(library(shinytitle))
shhh(library(dplyr))
shhh(library(ggplot2))
shhh(library(DT))
shhh(library(xfun))
shhh(library(metathis))
shhh(library(shinyalert))
shhh(library(shinytest2))
shhh(library(rstudioapi))
shhh(library(bslib))
shhh(library(dfeshiny))
shhh(library(ggiraph))

# Enable bookmarking so that input choices are shown in the url ---------------
enableBookmarking("url")
# Dependencies needed for testing or CI but not for the app -------------------
# Including them here keeps them in renv but avoids the app needlessly loading
# them, saving on load time.
if (FALSE) {
shhh(library(shinytest2))
shhh(library(testthat))
}

# Source scripts --------------------------------------------------------------

# Source any scripts here. Scripts may be needed to process data before it gets
# to the server file.
# to the server file or to hold custom functions to keep the main files shorter
#
# It's best to do this here instead of the server file, to improve performance.

# Source script for loading in data
source("R/read_data.R")

# Source custom functions script
source("R/utils.R")

# Source all files in the ui_panels folder
lapply(list.files("R/ui_panels/", full.names = TRUE), source)

# Set global variables --------------------------------------------------------

site_title <- "Department for Education (DfE) Shiny Template"
site_title <- "Department for Education (DfE) Shiny Template" # name of app
parent_pub_name <- "Statistical publication" # name of source publication
parent_publication <- # link to source publication
"https://explore-education-statistics.service.gov.uk/find-statistics/apprenticeships"

# Set the URLs that the site will be published to
site_primary <- "https://department-for-education.shinyapps.io/dfe-shiny-template/"
site_overflow <- "https://department-for-education.shinyapps.io/dfe-shiny-template-overflow/"

# Combine URLs into list for disconnect function
# We can add further mirrors where necessary. Each one can generally handle
# about 2,500 users simultaneously
sites_list <- c(site_primary, site_overflow)

# Update this with your parent
# publication name (e.g. the EES publication)
ees_pub_name <- "Statistical publication"

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

# Read in the data
# End of global variables -----------------------------------------------------

# Enable bookmarking so that input choices are shown in the url ---------------
enableBookmarking("url")

# Read in the data ------------------------------------------------------------
df_revbal <- read_revenue_data() %>%
mutate(school_phase = case_when(
school_phase == "All LA maintained schools" ~ "All local authority maintained schools",
Expand All @@ -74,6 +104,7 @@ df_areas <- df_revbal %>%
) %>%
distinct()

## Extract lists for use in drop downs ----------------------------------------
choices_las <- df_areas %>%
filter(geographic_level == "Local authority") %>%
select(geographic_level, area_name = la_name) %>%
Expand All @@ -89,20 +120,4 @@ choices_areas <- df_areas %>%
) %>%
rbind(choices_las)

choices_years <- unique(df_revbal$time_period)

choices_phase <- unique(df_revbal$school_phase)

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(
class = "govuk-details__summary-text",
label
)
),
shiny::tags$div(contents)
)
}
15 changes: 15 additions & 0 deletions renv.lock
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,21 @@
],
"Hash": "99b79fcbd6c4d1ce087f5c5c758b384f"
},
"dfeR": {
"Package": "dfeR",
"Version": "0.3.0",
"Source": "GitHub",
"RemoteType": "github",
"RemoteUsername": "dfe-analytical-services",
"RemoteRepo": "dfeR",
"RemoteRef": "main",
"RemoteSha": "6f5aca112e8fa0f35541c4a987cea6222302f89d",
"RemoteHost": "api.github.com",
"Requirements": [
"lifecycle"
],
"Hash": "1ecf7c371ee428eebb9234de2d48c05a"
},
"dfeshiny": {
"Package": "dfeshiny",
"Version": "0.1.1",
Expand Down
Loading

0 comments on commit 9a3a648

Please sign in to comment.