Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E1 second graph addition #2

Open
wants to merge 75 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
ffbf958
Conflict testing
alex-bruce May 2, 2024
5269429
Testing commit
Cormac-Murray May 8, 2024
2d2c8dd
removing test comment
MahriScot May 16, 2024
d12e6ec
Added code to keep app active longer for accessibility. Also set the …
alex-bruce May 17, 2024
e04dbed
Started adding functions and moving setup to its own file
alex-bruce May 17, 2024
ab35b55
EF2 updated
Cormac-Murray May 28, 2024
e8e1d47
EF3 updated.
Cormac-Murray May 28, 2024
975aa1b
EF4 updated.
Cormac-Murray May 28, 2024
9027283
Ef5 updated.
Cormac-Murray May 28, 2024
6b96e33
EQ Updates
Cormac-Murray May 30, 2024
9965ec3
Fixing tabName 'object not found' error
alex-bruce Jun 5, 2024
93ad79e
Fixing tabName 'object not found' error
alex-bruce Jun 5, 2024
0926acf
Fixing tabName 'object not found' error
alex-bruce Jun 5, 2024
5ff4bb1
Added initial graph to E1
alex-bruce Jun 18, 2024
bb183bf
Removed x-axis tick labels 'tickangle' attribute to make them reactive
alex-bruce Jun 18, 2024
571a2e6
Changed E1 legend string wrap width
alex-bruce Jun 18, 2024
e3ee863
Adding tab text styling
alex-bruce Jun 19, 2024
f9d1a11
Added data prep file
alex-bruce Jun 19, 2024
0b41b34
Moved nav buttons fluidRow into mainPanel section to keep them at the…
alex-bruce Jun 21, 2024
7864e36
Applying fix for indicator content spacing
alex-bruce Jun 27, 2024
a92d511
Update README.md
alex-bruce Jun 28, 2024
9161aaa
Minor grammar fix in intro
alex-bruce Jul 12, 2024
1e3ee4d
2nd graph added for E1
MahriScot Jul 22, 2024
21e66f3
added archive/
MahriScot Jul 22, 2024
0162b08
E1 graph - added margin/padding around axis and graph's title. Also a…
MahriScot Jul 25, 2024
0dd69c4
EQ1 graph and server updates
Cormac-Murray Jul 29, 2024
fb46e51
Outlining indicator alt text method
alex-bruce Jul 29, 2024
a232c15
E1 2nd graph - xasis changes.
MahriScot Jul 30, 2024
0241130
EQ1 Chart Updates
Cormac-Murray Aug 2, 2024
731eb05
changing filter names so they include indicator e.g. "unique_area_typ…
MahriScot Aug 8, 2024
e3eea1a
EF4 Server
alex-bruce Aug 7, 2024
2167d99
EF4 progress
alex-bruce Aug 8, 2024
7e3cd5b
EF4 graph v0.1
alex-bruce Aug 13, 2024
b7f8fb7
2x E1 warning errors fixed:
MahriScot Aug 15, 2024
ae42505
Creation of second EQ1 chart, with accompanying data.
Cormac-Murray Aug 19, 2024
2bad464
EF4 graph work
alex-bruce Aug 19, 2024
044e753
Changed page layout method EF4, EF2, T1
alex-bruce Aug 23, 2024
c320c1d
Changing E1 graph code from just using plotly to running it through g…
MahriScot Aug 29, 2024
388a547
E1 graph 1 scale taken away - will fix and add back next week
MahriScot Aug 29, 2024
03a7528
Updates to page layout for EQ1 and EF5.
Cormac-Murray Aug 30, 2024
f2e40e5
Apply fluidRow changes to the Person-centred and Safe indicators, as …
Cormac-Murray Sep 2, 2024
ccb69cf
E1 plot 1 scale changed
MahriScot Sep 3, 2024
76a320d
Updated E1 tab to use boxes
alex-bruce Sep 4, 2024
443e472
Removed bslib package
alex-bruce Sep 5, 2024
b3c7c19
Updated sidebar to include updated indicators
alex-bruce Sep 5, 2024
aef5183
Added loading spinner to E1 graph 1
alex-bruce Sep 5, 2024
489e490
Created phs_spinner function to apply spinner to all plots more easily
alex-bruce Sep 5, 2024
e273107
Added spinner to E1 graph 2
alex-bruce Sep 5, 2024
316f9a2
Apply fluidRow to all remaining pages with infographics.
Cormac-Murray Sep 6, 2024
07d2a09
Added package text for purrr
alex-bruce Sep 9, 2024
f552716
Updates to E1 chart selection and lines.
Cormac-Murray Sep 17, 2024
2a3f96e
Various css adjustments to Scotland Hub Tab
alex-bruce Sep 20, 2024
b87d93d
EF4 graph changed to ggplot and run through plotly. E1 graph2 title c…
MahriScot Sep 25, 2024
3533edd
EQ1 graphs now ggplot before plotly. Graph titles reworded and positi…
MahriScot Sep 26, 2024
0acc903
E1 graph 1 now shows data when page is loaded
MahriScot Sep 26, 2024
78bac16
EQ1 - first graph now showing legend, also rounded all values
MahriScot Sep 27, 2024
38930f4
EF4 graph now shows a legend
MahriScot Sep 27, 2024
9deb855
E1 graph one now shows legend
MahriScot Sep 27, 2024
a187ef9
phsstyles colours now used in graphs - E1, EF4, EQ1.
MahriScot Sep 27, 2024
ea95bce
Added some spacing between page titles and graphs.
MahriScot Sep 27, 2024
bfabddb
Create data tables on E1 page, along with option to download.
Cormac-Murray Oct 1, 2024
12e3bf5
Added borders to Scot Hub boxes and changed box header colour
alex-bruce Oct 1, 2024
29cfc25
Changed Scot Hub header colour to phs teal 10%
alex-bruce Oct 1, 2024
e616ff0
Put E1 tables within collapsed boxes.
Cormac-Murray Oct 1, 2024
1772813
Added password protection
alex-bruce Oct 1, 2024
c4c7726
Remove highlight column from second E1 downloadable table.
Cormac-Murray Oct 2, 2024
976294b
Adding tables and download option to EF4.
Cormac-Murray Oct 3, 2024
a93b3b2
Create tables and download buttons for EQ1.
Cormac-Murray Oct 3, 2024
d5d5a45
Set the collapsable tables to be uncollapsed at load.
Cormac-Murray Oct 3, 2024
57c636d
Updated password protection
alex-bruce Oct 7, 2024
8cc1e98
Updated password protection
alex-bruce Oct 7, 2024
6182306
Updated .gitignore
alex-bruce Oct 7, 2024
b5bfbd3
Minor Scot Hub fixes
alex-bruce Oct 7, 2024
f4a8b41
Update table headers and give downloadable csv files more descriptive…
Cormac-Murray Oct 7, 2024
18c7f22
Scotland Hub wording and variable values changed and linked to alt te…
MahriScot Oct 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,23 @@
.Rproj.user/
*.Rproj

# Folder readme
FOLDER_INFO.txt
# Deployment secrets

# Credentials script
create_credentials.R
# Constants file
constants.R

# Data prep script
data_preparation.R

# 'data' folder #
# folders to ignrore
admin/
archive/
data/

# infographics folder
drafts/
www/infographics


# Common text files that may contain data #
*.[cC][sS][vV]
*.[tT][xX][tT]
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# MHQI-Dashboard
The Mental Health Team's repo for the Mental Health Quality Indicators Dashboard

## Maintaining
This dashboard makes use of a file 'stylesheet.css' (which can be found in the www folder - where it must remain in order to work) to define styling of various elements. This styling overrides the default styling set by the Shiny package and enables styling to be changed once in one place and affect every incidence of that element. As a result, editing aesthetics and certain behaviours of this dashboard should be a much simpler process.

To edit an element you need to know what 'class(es)' refers to the element. If you need to find out the class(es) of a particular element you can run the app within RStudio and right click on the element you are interested in. Then click "inspect" and it will bring up the developer window with the relevant bits of code.

76 changes: 62 additions & 14 deletions app.R
Original file line number Diff line number Diff line change
@@ -1,50 +1,68 @@
### Mental Health Quality Indicators Dashboard

# Loading packages
library(phsstyles)
library(plotly)
library(ggplot2) # adding for testing using this before plotly
library(dplyr)
library(purrr)
library(purrr) # for map function to load multiple files
library(stringr)
library(shiny)
library(shinydashboard)
library(fresh) # for customising shinydashboard look
library(shinyWidgets)

library(forcats) # added by mahri for fct_reorder() in graph
library(gotop) # for return to top button
library(shinycssloaders) # for graph loading spinners
library(DT)
library(shinymanager) # password protection

# Data import section ----------------------------------------------------

# Source constants used throughout app
source("scot_hub_data.R")
source("setup.R")
source("data_preparation.R")

# 6. sourcing functions created for app (see functions folder) -------------------------------
list.files("functions") %>%
map(~ source(paste0("functions/", .)))

# # 6. sourcing functions created for app (see functions folder) -------------------------------
# list.files("functions") %>%
# map(~ source(paste0("functions/", .)))
#* Read in credentials for password-protecting the app ----
# credentials <- readRDS("admin/credentials.rds") # Un-comment if password protection needed

# Source the ui file ----
### [ UI section ] -------------------------------------------------------------

# ui <- source('ui.R', local = TRUE)$value

ui <- dashboardPage(

ui <-
# secure_app( # Un-comment if password protection is needed.
dashboardPage(

dashboardHeader(title = "MH Quality Indicators"),

dashboardSidebar(source("modules/sidebar_ui.R", local = TRUE)$value),

# Define how the various pages of the dashboard look
dashboardBody(

## Source styling for shinydashboard elements
# - must be before stylesheet so that it doesn't override the css file
source("www/dashboard_style.R", local = TRUE)$value,

## load css stylesheet that defines how things look
tags$head(includeCSS("www/stylesheet.css")),


## Tabs ----
tabItems(
# [Introduction Tab] ----------------------------------------------------
# [Introduction Tab] ----
source("modules/introduction_ui.R", local = TRUE)$value,


# [Scotland Hub Tab] ----------------------------------------------------
# [Scotland Hub Tab] ----
source("modules/scot_hub_ui.R", local = TRUE)$value,

## Sourcing ui sections for each indicator -------------------------------
## Sourcing ui sections for each indicator ----
# [Timely] ----
source("modules/indicators/T1_ui.R", local = TRUE)$value,
source("modules/indicators/T2_ui.R", local = TRUE)$value,
Expand Down Expand Up @@ -81,14 +99,44 @@ ui <- dashboardPage(

) # End of tabItems
) # End of dashboardBody
) # End of UI
) # End of dashboardPage
# ) # End of password-protection wrapper

# Server ----------------------------------------------------


### [ Server ] -----------------------------------------------------------------
server <- function(input, output, session) {

##* Shinymanager authorisation ----
# Un-comment this section to password protect the app.
# Re-comment out to remove password protection on launch day.
# res_auth <- secure_server(
# check_credentials = check_credentials(credentials)
# )
#
# output$auth_output <- renderPrint({
# reactiveValuesToList(res_auth)
# })

# Navigation buttons ----
source("modules/nav_buttons_server.R", local = TRUE)

# Indicator servers
source("modules/indicators/E1_server.R", local = TRUE)
source("modules/indicators/EQ1_server.R", local = TRUE)
source("modules/indicators/EF4_server.R", local = TRUE)


# Keep dashboard active indefinitely to meet accessibility requirements
# (Keep at the end of server)
auto_invalidate <- reactiveTimer(10000)
observe({
auto_invalidate()
cat(".")
})
}

# Sets language right at the top of source (required this way for screen readers)
attr(ui, "lang") = "en"

shinyApp(ui, server)
47 changes: 47 additions & 0 deletions data_preparation.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
### Data preparation script
# N.B. do not use any direct filepaths, ony relational ones

### [Indicators] ----
## E1 ----
E1_data <- read.csv("data/E1.csv") %>%
rename(dd_bed_days = delayed_discharge_bed_days,
fyear = financial_year)

E1_area_types <- E1_data %>%
distinct(area_type) %>% pull(area_type)

# For E1 plot 2:
E1_fyear <- E1_data %>%
distinct(fyear) %>%
pull(fyear)

## EQ1 ----
EQ1_data <- read.csv("data/EQ1.csv")

unique_area_types <- EQ1_data %>%
distinct(area_type) %>% pull(area_type)

# For EQ1 plot 2:
EQ1_reformatted_data <- read.csv("data/EQ1_Reformatted.csv")%>%
mutate(Rate = round(Rate)) # because values are e.g. "3158.23942548425913"

unique_area_types_reformatted <- EQ1_reformatted_data %>%
distinct(area_type) %>% pull(area_type)


## EF4 ----
EF4_data <- read.csv("data/EF4.csv") %>%
select(fyear, hb_name, measure, value)

EF4_fyear <- EF4_data %>%
distinct(fyear) %>% pull(fyear)

EF4_hb_names <- EF4_data %>%
distinct(hb_name) %>% pull(hb_name)

EF4_trend_measures <- c('Mental Health Expenditure (%)', 'CAMHS Expenditure (%)')

# EF4_trend_measures <- EF4_data %>%
# distinct(measure) %>% pull(measure) %>%
# filter(measure = )

7 changes: 7 additions & 0 deletions functions/core_functions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Load data from shiny_app/data ----
load_csv_file <- function(csv){
# Given a .csv file name in shiny_app/data
# this function loads it as a variable with the same name as the
# file apart from the extension
assign(gsub(".csv", "", csv), read.csv(paste0("data/", csv)), envir = .GlobalEnv)
}
70 changes: 70 additions & 0 deletions functions/plot_functions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
### Functions used in plots throughout the app

## PHS colour spinner ----

phs_spinner <- function(plot_name){
withSpinner(
plotlyOutput(plot_name, width = "100%"),
type = 8, size = 0.7,
color = "#AF69A9", # color.background = "#E1C7DF",
caption = "Loading...",
hide.ui = FALSE
)
}

## No Data function ----
# Function defining what is shown when there is no data to be presented:

noDataPlot <- function(line_colour){

noDataPlot_text <- list(
x = 5,
y = 2,
font = list(color = line_colour, size = 20),
text = paste0("No discharges found for these selections."),
xref = "x",
yref = "y",
showarrow = FALSE
)

# Visualise an empty graph with the above message in the middle.

plot_ly() %>%
layout(annotations = noDataPlot_text,
yaxis = list(showline = FALSE,
showticklabels = FALSE,
showgrid = FALSE),
xaxis = list(showline = FALSE,
showticklabels = FALSE,
showgrid = FALSE)) %>%
config(displayModeBar = FALSE,
displaylogo = F, editable = F)

}

### Scatter Line Plot Function ----
# Aesthetic attributes for line graphs

phs_scatterPlot <- function(plot_data, # Graph reactive ouput
x_var, # variable on x axis
y_var, # variable on y axis
tooltip, # tooltip object name
line_var # line variable name
)
{

plotly(
data = plot_data(),
x = ~x_var, y = ~y_var,
text = tooltip, hoverinfo = "text",
color = ~line_var,
colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), # line colours
type = 'scatter', mode = 'lines+markers',
# width = 600, height = 300,
line = list(width = 2),
linetype = ~line_var,
linetypes = c("solid", "dash"),
marker = list(size = 8),
name = ~str_wrap(line_var, 19))

}
9 changes: 9 additions & 0 deletions indicator_alt_text.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
max_year <- 2024

EF1 <- read_csv('data/EF1.csv')

EF1_rate <- EF1$rate %>%
filter(fyear = max_year)

EF1_lag_rate <- EF1$rate %>%
filter(fyear = (max_year-1))
2 changes: 1 addition & 1 deletion modules/appendix_ui.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tabItem(tabName = appendix_tab,
tabItem(tabName = "appendix_tab",
fluidPage(
titlePanel(h1("T1 - % of people who commence psychological therapy
based treatment within 18 weeks of referral"),
Expand Down
Loading