From ffbf958fa4c1e41ec746c07699b9de5ceeead01f Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Thu, 2 May 2024 16:14:15 +0100 Subject: [PATCH 01/75] Conflict testing --- app.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app.R b/app.R index a98ae23..29113e3 100644 --- a/app.R +++ b/app.R @@ -1,3 +1,5 @@ +# Loading packages test + library(phsstyles) library(dplyr) library(purrr) From 5269429192fa867cbedf941c4cdc7c0b1b63d8bf Mon Sep 17 00:00:00 2001 From: Cormac-Murray Date: Wed, 8 May 2024 10:42:56 +0100 Subject: [PATCH 02/75] Testing commit --- app.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.R b/app.R index 29113e3..da2e7df 100644 --- a/app.R +++ b/app.R @@ -10,7 +10,7 @@ library(shinyWidgets) # Data import section ---------------------------------------------------- - +# This is a comment to test workflow conflicts # Source constants used throughout app source("scot_hub_data.R") From 2d2c8dd84e8015034da67cd25d06c7bb093ab936 Mon Sep 17 00:00:00 2001 From: MahriScot Date: Thu, 16 May 2024 12:16:59 +0100 Subject: [PATCH 03/75] removing test comment --- app.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.R b/app.R index da2e7df..29113e3 100644 --- a/app.R +++ b/app.R @@ -10,7 +10,7 @@ library(shinyWidgets) # Data import section ---------------------------------------------------- -# This is a comment to test workflow conflicts + # Source constants used throughout app source("scot_hub_data.R") From d12e6ecd10ca31c1dcff3c3fa94b6f30196f8246 Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Fri, 17 May 2024 16:44:34 +0100 Subject: [PATCH 04/75] Added code to keep app active longer for accessibility. Also set the language attribute to English for screen readers. --- app.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app.R b/app.R index 29113e3..ff6fb2b 100644 --- a/app.R +++ b/app.R @@ -91,6 +91,16 @@ server <- function(input, output, session) { # Navigation buttons ---- source("modules/nav_buttons_server.R", local = TRUE) + # Keep dashboard active indefinnitely 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) From e04dbed4f10ea0e91ed46218e5b2e9bd7feef8fd Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Fri, 17 May 2024 16:47:03 +0100 Subject: [PATCH 05/75] Started adding functions and moving setup to its own file --- functions/core_functions.R | 7 +++++++ setup.R | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 functions/core_functions.R create mode 100644 setup.R diff --git a/functions/core_functions.R b/functions/core_functions.R new file mode 100644 index 0000000..8fceaeb --- /dev/null +++ b/functions/core_functions.R @@ -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) +} diff --git a/setup.R b/setup.R new file mode 100644 index 0000000..e5c393e --- /dev/null +++ b/setup.R @@ -0,0 +1,38 @@ +### Loading required packages ---- + +### Load functions ---- +source("functions/core_functions.R") +source("functions/plot_functions.R") + +### Load in data ---- + +# Load in data to app_data +# Find all rds files in shiny_app/data +csv_files <- list.files(path="data/", pattern="*.csv") +for (csv in csv_files){ + load_csv_file(csv) +} + + +### Repeated plotting code ---- + +# Buttons to remove from plotly plots +bttn_remove <- list( + 'select2d', + 'lasso2d', + 'zoomIn2d', + 'zoomOut2d', + 'autoScale2d', + 'toggleSpikelines', + 'hoverCompareCartesian', + 'hoverClosestCartesian' +) + +# Go to top button +gotop::use_gotop( + src = "fas fa-chevron-circle-up", # css class from Font Awesome + color = navy, # color + opacity = 0.8, # transparency + width = 50, # size + appear = 80 # number of pixels before appearance +) \ No newline at end of file From ab35b55aa5034f0f385ebb355369cd4ddd7d8404 Mon Sep 17 00:00:00 2001 From: Cormac-Murray Date: Tue, 28 May 2024 15:38:13 +0100 Subject: [PATCH 06/75] EF2 updated --- modules/indicators/EF2_ui.R | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/modules/indicators/EF2_ui.R b/modules/indicators/EF2_ui.R index d66b28a..330d168 100644 --- a/modules/indicators/EF2_ui.R +++ b/modules/indicators/EF2_ui.R @@ -1,9 +1,25 @@ tabItem(tabName = EF2_tab, fluidPage( - titlePanel("EF2"), + titlePanel("EF2 - Readmissions to hospital within 28 days of discharge"), mainPanel( - h3("You are on EF2"), - fluidRow( + img(src='infographics/EF2.png', + class = "infographic", + alt = paste0( + "The percentage of emergency readmissions within 28 days in ", + "Scotland was 7.3% for the year-long period ending 31 March ", + "2023. This compares with 7.8% for the year ending 31 March ", + "2022 and 9.3% for the year ending 31 March 2021.")), + br(), + p("The data for EF1 is sourced from ", + a(href="https://www.nssdiscovery.scot.nhs.uk/", + "Discovery"), + " using SMR04 data.", + a(href="https://publichealthscotland.scot/services/data-management/data-management-in-secondary-care-hospital-activity/scottish-morbidity-records-smr/completeness/", + "Data completeness"), + " for SMR04 was around 90% or better when the data was accessed.") + ), + + fluidRow( column(4, actionButton(inputId = "EF2_scot_hub_button", label = "Scotland Hub", icon = icon("home"), class = "navpageButton")), @@ -14,6 +30,6 @@ tabItem(tabName = EF2_tab, label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) - ) + ) # End of fluidPage + ) \ No newline at end of file From e8e1d475a6656e2b082e3d6b34051521bf4dc54f Mon Sep 17 00:00:00 2001 From: Cormac-Murray Date: Tue, 28 May 2024 15:52:23 +0100 Subject: [PATCH 07/75] EF3 updated. --- modules/indicators/EF3_ui.R | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/modules/indicators/EF3_ui.R b/modules/indicators/EF3_ui.R index 695d861..89cb93a 100644 --- a/modules/indicators/EF3_ui.R +++ b/modules/indicators/EF3_ui.R @@ -1,9 +1,26 @@ tabItem(tabName = EF3_tab, fluidPage( - titlePanel("EF3"), + titlePanel("EF3 - Total psychiatric inpatient beds per 100,000 population (NRAC adjusted)"), mainPanel( - h3("You are on EF3"), - fluidRow( + img(src='infographics/EF3.png', + class = "infographic", + alt = paste0( + "The total number of average available staffed beds per day ", + "for all psychiatric specialties in 2022/23 in Scotland was ", + "3,679 beds (i.e. 66.8 psychiatric beds per 100,000 ", + "population). This is a decrease from 67.5 beds per 100,000 ", + "population in 2021/22 and 68.8 beds per 100,000 population ", + "in 2020/21.")), + br(), + p("The numerator for EF3 is sourced from ", + a(href="https://publichealthscotland.scot/publications/acute-hospital-activity-and-nhs-beds-information-annual/", + "the Acute hospital activity and NHS beds information annual release publication, "), + "and the denominator is sourced from ", + a(href="https://www.publichealthscotland.scot/publications/resource-allocation-formula-nrac/resource-allocation-formula-nrac-for-nhsscotland-results-for-financial-year-2024-to-2025/", + "the National Resource Allocation publication.")) + ), + + fluidRow( column(4, actionButton(inputId = "EF3_scot_hub_button", label = "Scotland Hub", icon = icon("home"), class = "navpageButton")), @@ -14,6 +31,6 @@ tabItem(tabName = EF3_tab, label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) + ) # End of fluidPage ) ) \ No newline at end of file From 975aa1b5b6b72f6305df4c00a05916a50a30462c Mon Sep 17 00:00:00 2001 From: Cormac-Murray Date: Tue, 28 May 2024 16:00:24 +0100 Subject: [PATCH 08/75] EF4 updated. --- modules/indicators/EF3_ui.R | 2 +- modules/indicators/EF4_ui.R | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/modules/indicators/EF3_ui.R b/modules/indicators/EF3_ui.R index 89cb93a..0b5b214 100644 --- a/modules/indicators/EF3_ui.R +++ b/modules/indicators/EF3_ui.R @@ -32,5 +32,5 @@ tabItem(tabName = EF3_tab, class = "navpageButton")) ) ) # End of fluidPage - ) + ) \ No newline at end of file diff --git a/modules/indicators/EF4_ui.R b/modules/indicators/EF4_ui.R index 4da7d8d..441f76f 100644 --- a/modules/indicators/EF4_ui.R +++ b/modules/indicators/EF4_ui.R @@ -1,9 +1,24 @@ tabItem(tabName = EF4_tab, fluidPage( - titlePanel("EF4"), + titlePanel("EF4 - Total mental health spend as a % of total spend"), mainPanel( - h3("You are on EF4"), - fluidRow( + img(src='infographics/EF4.png', + class = "infographic", + alt = paste0( + "The total (net) mental health expenditure for 2021/22 was ", + "nearly £1,300 million for NHS Scotland, 8.8% of total NHS ", + "expenditure This is an increase from nearly £1,250 million ", + "in 2020/21, 8.8% of total NHS expenditure.")), + br(), + p("These data are sourced from data collected annually by Public Health Scotland (PHS) on expenditure within NHS Scotland, released in an ", + a(href="https://publichealthscotland.scot/media/17844/nhsscotland-mental-health-expenditure.xlsx", + "excel workbook "), + "which also includes data for organisations providing these services (14 territorial NHS Boards and the State Hospital at Carstairs Lanarkshire), as part of the ", + a(href="https://publichealthscotland.scot/publications/scottish-health-service-costs/scottish-health-service-costs-high-level-costs-summary-2021-to-2022/", + "annual release of National Statistics covering expenditure in the financial year 2021/22.")) + ), + + fluidRow( column(4, actionButton(inputId = "EF4_scot_hub_button", label = "Scotland Hub", icon = icon("home"), class = "navpageButton")), @@ -14,6 +29,6 @@ tabItem(tabName = EF4_tab, label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) - ) + ) # End of fluidPage + ) \ No newline at end of file From 9027283eb07a09074ecea395bdd70150e00178f1 Mon Sep 17 00:00:00 2001 From: Cormac-Murray Date: Tue, 28 May 2024 16:06:30 +0100 Subject: [PATCH 09/75] Ef5 updated. --- modules/indicators/EF5_ui.R | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/modules/indicators/EF5_ui.R b/modules/indicators/EF5_ui.R index 82bbb57..c125162 100644 --- a/modules/indicators/EF5_ui.R +++ b/modules/indicators/EF5_ui.R @@ -1,5 +1,19 @@ tabItem(tabName = EF5_tab, fluidPage( + titlePanel("EF5 - % of did not attend appointments for community based services of people with mental health problems"), + mainPanel( + img(src='infographics/EF5.png', + class = "infographic", + alt = paste0( + "The percentage of people who did not attend their ", + "appointment for mental health problems at community based ", + "services ranged from 8% to 19% for the quarter ending 30 ", + "June 2023.")), + br(), + p("The data for EF5 is sourced is sourced from health board returns, which may be incomplete.") + ), + + fluidPage( titlePanel("EF5"), mainPanel( h3("You are on EF5"), @@ -16,4 +30,5 @@ tabItem(tabName = EF5_tab, ) ) ) +) # End of fluidPage ) \ No newline at end of file From 6b96e33da1f838fe36bba5235ad3df6dd71ca778 Mon Sep 17 00:00:00 2001 From: Cormac-Murray Date: Thu, 30 May 2024 14:55:11 +0100 Subject: [PATCH 10/75] EQ Updates --- modules/indicators/EF5_ui.R | 11 +++-------- modules/indicators/EQ1_ui.R | 20 ++++++++++++++++---- modules/indicators/EQ2_ui.R | 19 ++++++++++++++----- modules/indicators/EQ4_ui.R | 21 ++++++++++++++++----- 4 files changed, 49 insertions(+), 22 deletions(-) diff --git a/modules/indicators/EF5_ui.R b/modules/indicators/EF5_ui.R index c125162..0d54427 100644 --- a/modules/indicators/EF5_ui.R +++ b/modules/indicators/EF5_ui.R @@ -13,10 +13,7 @@ tabItem(tabName = EF5_tab, p("The data for EF5 is sourced is sourced from health board returns, which may be incomplete.") ), - fluidPage( - titlePanel("EF5"), - mainPanel( - h3("You are on EF5"), + fluidRow( column(4, actionButton(inputId = "EF5_scot_hub_button", label = "Scotland Hub", icon = icon("home"), @@ -28,7 +25,5 @@ tabItem(tabName = EF5_tab, label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) - ) -) # End of fluidPage -) \ No newline at end of file + ) # End of fluidPage + ) \ No newline at end of file diff --git a/modules/indicators/EQ1_ui.R b/modules/indicators/EQ1_ui.R index 2aa832f..4990e3e 100644 --- a/modules/indicators/EQ1_ui.R +++ b/modules/indicators/EQ1_ui.R @@ -1,8 +1,21 @@ tabItem(tabName = EQ1_tab, fluidPage( - titlePanel("EQ1"), + titlePanel("EQ1 - Premature mortality rate = Standardised mortality rate for persons in contact with mental health services"), mainPanel( - h3("You are on EQ1"), + img(src='infographics/EQ1.png', + class = "infographic", + alt = paste0( + "The mortality rate for persons in contact with the mental ", + "health service in Scotland is 2.71 times higher than the ", + "mortality rate for the general population when ", + "standardised by age and sex in 2021/22. This compares ", + "with 2.62 in 2020/21.")), + br(), + p("The data for EQ1 are sourced from SMR04 and death registrations ", + a(href="https://www.nrscotland.gov.uk/statistics-and-data/statistics/statistics-by-theme/vital-events/deaths/deaths-background-information", + "(National Records of Scotland; NRS).")) + ), + fluidRow( column(4, actionButton(inputId = "EQ1_scot_hub_button", label = "Scotland Hub", icon = icon("home"), @@ -14,6 +27,5 @@ tabItem(tabName = EQ1_tab, label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) + ) # End of fluidPage ) -) \ No newline at end of file diff --git a/modules/indicators/EQ2_ui.R b/modules/indicators/EQ2_ui.R index 7ef7e69..d0235fd 100644 --- a/modules/indicators/EQ2_ui.R +++ b/modules/indicators/EQ2_ui.R @@ -1,8 +1,18 @@ tabItem(tabName = EQ2_tab, fluidPage( - titlePanel("EQ2"), + titlePanel("EQ2 - Number of emergency detention certificates (EDCs) per 100,000 population"), mainPanel( - h3("You are on EQ2"), + img(src='infographics/EQ2.png', + class = "infographic", + alt = paste0( + "In Scotland in 2022/23, the number of emergency detention ", + "certificates per 100,000 population was 60.0. This is a ", + "slight increase from 59.5 in 2021/22.")), + br(), + p("This data is sourced from the ", + a(href="https://www.mwcscot.org.uk/publications?type=44&leg=54", + "Mental Welfare Commission.")) + ), fluidRow( column(4, actionButton(inputId = "EQ2_scot_hub_button", label = "Scotland Hub", icon = icon("home"), @@ -14,6 +24,5 @@ tabItem(tabName = EQ2_tab, label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) - ) -) \ No newline at end of file + ) # End of fluidPage + ) \ No newline at end of file diff --git a/modules/indicators/EQ4_ui.R b/modules/indicators/EQ4_ui.R index a7c0ccf..956da13 100644 --- a/modules/indicators/EQ4_ui.R +++ b/modules/indicators/EQ4_ui.R @@ -1,8 +1,20 @@ tabItem(tabName = EQ4_tab, fluidPage( - titlePanel("EQ4"), + titlePanel("EQ4 - % of under 18 year old psychiatric admissions admitted out with NHS specialist Child and Adolescent Mental Health (CAMH) wards"), mainPanel( - h3("You are on EQ4"), + img(src='infographics/EQ4.png', + class = "infographic", + alt = paste0( + "30.1% of under 18 year old psychiatric admissions were ", + "admitted outwith NHS specialist CAMH wards during the ", + "year-long period ending 31 March 2023. This compares with ", + "35.5% during the year ending 31 March 2022, and 29.3% ", + "during the year ending 31 March 2021.")), + br(), + p("The data for EQ4 is sourced from ", + a(href="https://www.publichealthscotland.scot/services/discovery/#section-1-1", + "Discovery.")) + ), fluidRow( column(4, actionButton(inputId = "EQ2_prevButton", label = "Previous Page", icon = icon("arrow-left"), @@ -11,6 +23,5 @@ tabItem(tabName = EQ4_tab, label = "Scotland Hub", icon = icon("home"), class = "navpageButton")) ) - ) - ) -) \ No newline at end of file + ) # End of fluidPage + ) \ No newline at end of file From 9965ec389ba75f2de58823f6e58ed955f3ee960b Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Wed, 5 Jun 2024 17:27:42 +0100 Subject: [PATCH 11/75] Fixing tabName 'object not found' error --- modules/indicators/E1_ui.R | 2 +- modules/indicators/EF1_ui.R | 2 +- modules/indicators/EF2_ui.R | 2 +- modules/indicators/EF3_ui.R | 2 +- modules/indicators/EF4_ui.R | 2 +- modules/indicators/EF5_ui.R | 2 +- modules/indicators/EQ1_ui.R | 2 +- modules/indicators/EQ2_ui.R | 2 +- modules/indicators/EQ4_ui.R | 2 +- modules/indicators/P1_ui.R | 2 +- modules/indicators/P2_ui.R | 2 +- modules/indicators/P3_ui.R | 2 +- modules/indicators/P4_ui.R | 2 +- modules/indicators/S1_ui.R | 2 +- modules/indicators/S2_ui.R | 2 +- modules/indicators/S5_ui.R | 2 +- modules/indicators/T1_ui.R | 2 +- modules/indicators/T2_ui.R | 2 +- modules/indicators/T3_ui.R | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) diff --git a/modules/indicators/E1_ui.R b/modules/indicators/E1_ui.R index 5e55c2a..00e2e91 100644 --- a/modules/indicators/E1_ui.R +++ b/modules/indicators/E1_ui.R @@ -1,4 +1,4 @@ -tabItem(tabName = E1_tab, +tabItem(tabName = "E1_tab", fluidPage( titlePanel(paste0( "E1 - ")), diff --git a/modules/indicators/EF1_ui.R b/modules/indicators/EF1_ui.R index 702ab63..69efbc5 100644 --- a/modules/indicators/EF1_ui.R +++ b/modules/indicators/EF1_ui.R @@ -1,4 +1,4 @@ -tabItem(tabName = EF1_tab, +tabItem(tabName = "EF1_tab", fluidPage( titlePanel("EF1 - Rate of Emergency Bed Days for Adults"), mainPanel( diff --git a/modules/indicators/EF2_ui.R b/modules/indicators/EF2_ui.R index 330d168..131282a 100644 --- a/modules/indicators/EF2_ui.R +++ b/modules/indicators/EF2_ui.R @@ -1,4 +1,4 @@ -tabItem(tabName = EF2_tab, +tabItem(tabName = "EF2_tab", fluidPage( titlePanel("EF2 - Readmissions to hospital within 28 days of discharge"), mainPanel( diff --git a/modules/indicators/EF3_ui.R b/modules/indicators/EF3_ui.R index 0b5b214..c543611 100644 --- a/modules/indicators/EF3_ui.R +++ b/modules/indicators/EF3_ui.R @@ -1,4 +1,4 @@ -tabItem(tabName = EF3_tab, +tabItem(tabName = "EF3_tab", fluidPage( titlePanel("EF3 - Total psychiatric inpatient beds per 100,000 population (NRAC adjusted)"), mainPanel( diff --git a/modules/indicators/EF4_ui.R b/modules/indicators/EF4_ui.R index 441f76f..b56182f 100644 --- a/modules/indicators/EF4_ui.R +++ b/modules/indicators/EF4_ui.R @@ -1,4 +1,4 @@ -tabItem(tabName = EF4_tab, +tabItem(tabName = "EF4_tab", fluidPage( titlePanel("EF4 - Total mental health spend as a % of total spend"), mainPanel( diff --git a/modules/indicators/EF5_ui.R b/modules/indicators/EF5_ui.R index 0d54427..c119fc2 100644 --- a/modules/indicators/EF5_ui.R +++ b/modules/indicators/EF5_ui.R @@ -1,4 +1,4 @@ -tabItem(tabName = EF5_tab, +tabItem(tabName = "EF5_tab", fluidPage( titlePanel("EF5 - % of did not attend appointments for community based services of people with mental health problems"), mainPanel( diff --git a/modules/indicators/EQ1_ui.R b/modules/indicators/EQ1_ui.R index 4990e3e..e5f2df4 100644 --- a/modules/indicators/EQ1_ui.R +++ b/modules/indicators/EQ1_ui.R @@ -1,4 +1,4 @@ -tabItem(tabName = EQ1_tab, +tabItem(tabName = "EQ1_tab", fluidPage( titlePanel("EQ1 - Premature mortality rate = Standardised mortality rate for persons in contact with mental health services"), mainPanel( diff --git a/modules/indicators/EQ2_ui.R b/modules/indicators/EQ2_ui.R index d0235fd..711005e 100644 --- a/modules/indicators/EQ2_ui.R +++ b/modules/indicators/EQ2_ui.R @@ -1,4 +1,4 @@ -tabItem(tabName = EQ2_tab, +tabItem(tabName = "EQ2_tab", fluidPage( titlePanel("EQ2 - Number of emergency detention certificates (EDCs) per 100,000 population"), mainPanel( diff --git a/modules/indicators/EQ4_ui.R b/modules/indicators/EQ4_ui.R index 956da13..9dbbf25 100644 --- a/modules/indicators/EQ4_ui.R +++ b/modules/indicators/EQ4_ui.R @@ -1,4 +1,4 @@ -tabItem(tabName = EQ4_tab, +tabItem(tabName = "EQ4_tab", fluidPage( titlePanel("EQ4 - % of under 18 year old psychiatric admissions admitted out with NHS specialist Child and Adolescent Mental Health (CAMH) wards"), mainPanel( diff --git a/modules/indicators/P1_ui.R b/modules/indicators/P1_ui.R index 3b37a3a..f499d0d 100644 --- a/modules/indicators/P1_ui.R +++ b/modules/indicators/P1_ui.R @@ -1,4 +1,4 @@ -tabItem(tabName = P1_tab, +tabItem(tabName = "P1_tab", fluidPage( titlePanel(paste0("P1 - % of carers with a mental health condition that ", "felt supported to continue in their caring role")), diff --git a/modules/indicators/P2_ui.R b/modules/indicators/P2_ui.R index 45de465..d29808b 100644 --- a/modules/indicators/P2_ui.R +++ b/modules/indicators/P2_ui.R @@ -1,4 +1,4 @@ -tabItem(tabName = P2_tab, +tabItem(tabName = "P2_tab", fluidPage( titlePanel(paste0( "P2 - % of adults with mental health problems supported at home ", diff --git a/modules/indicators/P3_ui.R b/modules/indicators/P3_ui.R index 00123e2..92cf724 100644 --- a/modules/indicators/P3_ui.R +++ b/modules/indicators/P3_ui.R @@ -1,4 +1,4 @@ -tabItem(tabName = P3_tab, +tabItem(tabName = "P3_tab", fluidPage( titlePanel(paste0('P3 - % of replies for people with mental health ', 'problem that agree with statement ', diff --git a/modules/indicators/P4_ui.R b/modules/indicators/P4_ui.R index 4fad617..2af1342 100644 --- a/modules/indicators/P4_ui.R +++ b/modules/indicators/P4_ui.R @@ -1,4 +1,4 @@ -tabItem(tabName = P4_tab, +tabItem(tabName = "P4_tab", fluidPage( titlePanel(paste0("P4 - Number of people with advance statements ", "registered per year with the Mental Welfare ", diff --git a/modules/indicators/S1_ui.R b/modules/indicators/S1_ui.R index 007fae1..29be37c 100644 --- a/modules/indicators/S1_ui.R +++ b/modules/indicators/S1_ui.R @@ -1,4 +1,4 @@ -tabItem(tabName = S1_tab, +tabItem(tabName = "S1_tab", fluidPage( titlePanel("S1 - Suicide Rates per 100,000 population"), mainPanel( diff --git a/modules/indicators/S2_ui.R b/modules/indicators/S2_ui.R index cac62fa..7bbdc2a 100644 --- a/modules/indicators/S2_ui.R +++ b/modules/indicators/S2_ui.R @@ -1,4 +1,4 @@ -tabItem(tabName = S2_tab, +tabItem(tabName = "S2_tab", fluidPage( titlePanel(paste0("S2 - % of all discharged psychiatric inpatients ", "followed-up by community mental health services ", diff --git a/modules/indicators/S5_ui.R b/modules/indicators/S5_ui.R index b081287..585a528 100644 --- a/modules/indicators/S5_ui.R +++ b/modules/indicators/S5_ui.R @@ -1,4 +1,4 @@ -tabItem(tabName = S5_tab, +tabItem(tabName = "S5_tab", fluidPage( titlePanel( paste0( diff --git a/modules/indicators/T1_ui.R b/modules/indicators/T1_ui.R index 9792ebc..8095731 100644 --- a/modules/indicators/T1_ui.R +++ b/modules/indicators/T1_ui.R @@ -1,4 +1,4 @@ -tabItem(tabName = T1_tab, +tabItem(tabName = "T1_tab", fluidPage( titlePanel(h1("T1 - % of people who commence Psychological therapy based treatment within 18 weeks of referral"), diff --git a/modules/indicators/T2_ui.R b/modules/indicators/T2_ui.R index 0f71f23..28e2f07 100644 --- a/modules/indicators/T2_ui.R +++ b/modules/indicators/T2_ui.R @@ -1,4 +1,4 @@ -tabItem(tabName = T2_tab, +tabItem(tabName = "T2_tab", fluidPage( headerPanel(fluidRow("T2 - % of young people who commence treatment by specialist Child and Adolescent Mental Health services diff --git a/modules/indicators/T3_ui.R b/modules/indicators/T3_ui.R index 35964c4..c060c17 100644 --- a/modules/indicators/T3_ui.R +++ b/modules/indicators/T3_ui.R @@ -1,4 +1,4 @@ -tabItem(tabName = T3_tab, +tabItem(tabName = "T3_tab", fluidPage( titlePanel( paste0( From 93ad79edccbd7e37686ed8bdc07fa606daf221f8 Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Wed, 5 Jun 2024 17:41:31 +0100 Subject: [PATCH 12/75] Fixing tabName 'object not found' error --- modules/appendix_ui.R | 2 +- modules/scot_hub_ui.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/appendix_ui.R b/modules/appendix_ui.R index 162b143..ff18fb8 100644 --- a/modules/appendix_ui.R +++ b/modules/appendix_ui.R @@ -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"), diff --git a/modules/scot_hub_ui.R b/modules/scot_hub_ui.R index 609ba3f..8840bf6 100644 --- a/modules/scot_hub_ui.R +++ b/modules/scot_hub_ui.R @@ -1,4 +1,4 @@ -tabItem(tabName = scot_hub, +tabItem(tabName = "scot_hub", ### [Timely] --------------------------- From 0926acf2c7f8b9ec8e43b447d75f13437d4d8623 Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Wed, 5 Jun 2024 17:41:31 +0100 Subject: [PATCH 13/75] Fixing tabName 'object not found' error --- modules/introduction_ui.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/introduction_ui.R b/modules/introduction_ui.R index ffaac03..f070b12 100644 --- a/modules/introduction_ui.R +++ b/modules/introduction_ui.R @@ -1,4 +1,4 @@ -tabItem(tabName = intro, +tabItem(tabName = "intro", fluidPage( # titlePanel("Mental Health Quality Indicators Joint Collection Materials"), mainPanel( From 5ff4bb13cb8c6f5902d6aed77e6ebf70bc439d32 Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Tue, 18 Jun 2024 18:08:27 +0100 Subject: [PATCH 14/75] Added initial graph to E1 --- .gitignore | 5 +- app.R | 12 ++- functions/plot_functions.R | 29 +++++++ modules/indicators/E1_server.R | 147 +++++++++++++++++++++++++++++++++ modules/indicators/E1_ui.R | 61 ++++++++++---- setup.R | 29 ++++--- 6 files changed, 252 insertions(+), 31 deletions(-) create mode 100755 functions/plot_functions.R create mode 100644 modules/indicators/E1_server.R diff --git a/.gitignore b/.gitignore index 093f24e..8f1c5bf 100644 --- a/.gitignore +++ b/.gitignore @@ -15,10 +15,9 @@ constants.R # Data prep script data_preparation.R -# 'data' folder # +# folders to ignrore data/ - -# infographics folder +drafts/ www/infographics # Common text files that may contain data # diff --git a/app.R b/app.R index ff6fb2b..3cf0d9e 100644 --- a/app.R +++ b/app.R @@ -1,22 +1,28 @@ # Loading packages test library(phsstyles) +library(plotly) library(dplyr) library(purrr) +library(stringr) library(shiny) library(shinydashboard) library(fresh) # for customising shinydashboard look library(shinyWidgets) + + # 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/", .))) +list.files("functions") %>% + map(~ source(paste0("functions/", .))) # Source the ui file ---- @@ -90,7 +96,7 @@ server <- function(input, output, session) { # Navigation buttons ---- source("modules/nav_buttons_server.R", local = TRUE) - + source("modules/indicators/E1_server.R", local = TRUE) # Keep dashboard active indefinnitely to meet accessibility requirements # (Keep at the end of server) auto_invalidate <- reactiveTimer(10000) diff --git a/functions/plot_functions.R b/functions/plot_functions.R new file mode 100755 index 0000000..ed4cbc4 --- /dev/null +++ b/functions/plot_functions.R @@ -0,0 +1,29 @@ +# 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) + +} diff --git a/modules/indicators/E1_server.R b/modules/indicators/E1_server.R new file mode 100644 index 0000000..c9d05cf --- /dev/null +++ b/modules/indicators/E1_server.R @@ -0,0 +1,147 @@ +output$E1_plot1_areaType_output <- renderUI({ + shinyWidgets::pickerInput( + "E1_plot1_areaType", + label = "Select type of geography:", + choices = unique_area_types, + selected = "Health board") +}) + +output$E1_plot1_areaName_output <- renderUI({ + shinyWidgets::pickerInput( + "E1_plot1_areaName", + label = "Select area(s) (Maximum 5):", + choices = sort(unique(as.character( + E1_data$area_name + [E1_data$area_type %in% input$E1_plot1_areaType] + ))) + # , + # multiple = TRUE, + # options = list("max-options" = 5, + # `selected-text-format` = "count > 1") + ) +}) + +E1_plot1_Data <- reactive({ + E1_data %>% + select(fyear, area_type, area_name, dd_bed_days) %>% + filter(area_type %in% input$E1_plot1_areaType + & area_name %in% input$E1_plot1_areaName) +}) + +# Create the discharges line chart. + +output$E1_plot1 <- renderPlotly({ +# +# # # No data plot +# # if(sum(E1_plot1_Data()$dd_bed_days) == 0 & +# # !is.na(sum(E1_plot1_Data()$dd_bed_days))) +# # +# # { +# # noDataPlot(phs_colours("phs-purple")) +# # } +# # +# # else { +# + ### 3 - Tooltip creation ---- + + tooltip_E1 <- paste0("Financial year: ", + E1_plot1_Data()$fyear, + "
", + "Area of residence: ", + E1_plot1_Data()$area_name, + "
", + "Number of Bed Days: ", + E1_plot1_Data()$dd_bed_days) + + ### 4 - Create the main body of the chart ---- + + plot_ly(data = E1_plot1_Data(), + # Select your variables. + x = ~fyear, y = ~dd_bed_days, color = ~area_name, + colors = c("#0080FF"), # line colour - Dark blue for all lines + text = tooltip_E1, hoverinfo = "text", + type = 'scatter', mode = 'lines+markers', + # width = 600, height = 300, + line = list(width = 3), + marker = list(size = 12), + name = ~str_wrap(area_name, 14)) %>% # legend labels + + ### 7 - Graph title ---- + + # Make the graph title reactive. + + layout(title = + paste0( + "", + "Number of Delayed Discharge Bed Days", " by ", + input$E1_plot1_areaType, ",", + "
", + first(as.vector(E1_plot1_Data()$fyear)), + " to ", + last(as.vector(E1_plot1_Data()$fyear)), + "
", + "
" + ), + + separators = ".", + + yaxis = list( + exponentformat = "none", + separatethousands = TRUE, + range = c(0, max(E1_plot1_Data()$dd_bed_days, na.rm = TRUE) + + (max(E1_plot1_Data()$dd_bed_days, na.rm = TRUE)*0.1) + ), + title = paste0(c(rep(" ", 20), + input$E1_1_input_1, + rep(" ", 20), + rep("\n ", 3))), + showline = TRUE, + ticks = "outside" + ), + + xaxis = list( + tickangle = -45, + title = paste0(c("
", + "Financial year", + collapse = "")), # Don't think it's needed + showline = TRUE, + ticks = "outside" + ), + + margin = list(l = 90, r = 60, b = 180, t = 120), + title = list(size = 15), + font = list(size = 13), + # Legend + showlegend = TRUE, + legend = list(x = 1, + y = 1, + bgcolor = 'rgba(255, 255, 255, 0)', + bordercolor = 'rgba(255, 255, 255, 0)') + # legend = list(orientation = "h", # show entries horizontally + # xanchor = "center", # use center of legend as anchor + # x = 0.5, y = -0.9) # put legend in center of x-axis + ) %>% + + ### 13 - Remove unnecessary buttons from the modebar ---- + + config(displayModeBar = TRUE, + modeBarButtonsToRemove = bttn_remove, + displaylogo = F, editable = F) + + # } + +}) + + +### 15 - Table below graph creation ---- + +# output$E1_1_trend_table <- renderDataTable({ +# datatable(E1_plot1_Data(), +# style = 'bootstrap', +# class = 'table-bordered table-condensed', +# rownames = FALSE, +# options = list(pageLength = 16, autoWidth = TRUE, dom = 'tip'), +# colnames = c("Financial year", +# "Area of Residence", +# "Number of Bed Days")) +# }) diff --git a/modules/indicators/E1_ui.R b/modules/indicators/E1_ui.R index 00e2e91..2ccd172 100644 --- a/modules/indicators/E1_ui.R +++ b/modules/indicators/E1_ui.R @@ -1,20 +1,53 @@ tabItem(tabName = "E1_tab", fluidPage( titlePanel(paste0( - "E1 - ")), + "E1 - Number of days people spend in hospital when they are ", + "clinically ready to be discharged (per 1,000 population)")), mainPanel( - h3("You are on E1"), + tags$p("Below is a graph showing the changes over time."), + fluidRow( - column(4, actionButton(inputId = "E1_scot_hub_button", - label = "Scotland Hub", icon = icon("home"), - class = "navpageButton")), - column(4, actionButton(inputId = "P4_prevButton", - label = "Previous Page", icon = icon("arrow-left"), - class = "navpageButton")), - column(4, actionButton(inputId = "EF1_nextButton", - label = "Next Page", icon = icon("arrow-right"), - class = "navpageButton")) - ) + column(6,uiOutput("E1_plot1_areaType_output")), + column(6,uiOutput("E1_plot1_areaName_output")) + ), + + fluidRow( + plotlyOutput("E1_plot1" + # , + # width = "100%", + # height = "50%" + ) + ), + br(), + # dataTableOutput("diagnoses_table"), + br(), + br(), + + go_2_top_bttn, + + # tags$a(href = '#E1_top', + # icon("circle-arrow-up", + # lib = "glyphicon"), + # "Back to top"), + br(), + br(), + # ), # End of mainPanel + + + + + + fluidRow( + column(4, actionButton(inputId = "E1_scot_hub_button", + label = "Scotland Hub", icon = icon("home"), + class = "navpageButton")), + column(4, actionButton(inputId = "P4_prevButton", + label = "Previous Page", icon = icon("arrow-left"), + class = "navpageButton")), + column(4, actionButton(inputId = "EF1_nextButton", + label = "Next Page", icon = icon("arrow-right"), + class = "navpageButton")) ) - ) -) \ No newline at end of file + ) + ) +) diff --git a/setup.R b/setup.R index e5c393e..dd766ac 100644 --- a/setup.R +++ b/setup.R @@ -1,17 +1,17 @@ ### Loading required packages ---- ### Load functions ---- -source("functions/core_functions.R") -source("functions/plot_functions.R") +# source("functions/core_functions.R") +# source("functions/plot_functions.R") ### Load in data ---- -# Load in data to app_data -# Find all rds files in shiny_app/data -csv_files <- list.files(path="data/", pattern="*.csv") -for (csv in csv_files){ - load_csv_file(csv) -} +# # Load in data to app_data +# # Find all rds files in shiny_app/data +# csv_files <- list.files(path="data/", pattern="*.csv") +# for (csv in csv_files){ +# load_csv_file(csv) +# } ### Repeated plotting code ---- @@ -29,10 +29,17 @@ bttn_remove <- list( ) # Go to top button -gotop::use_gotop( +go_2_top_bttn <- gotop::use_gotop( src = "fas fa-chevron-circle-up", # css class from Font Awesome - color = navy, # color + color = phs_colors('phs-blue'), # color opacity = 0.8, # transparency width = 50, # size appear = 80 # number of pixels before appearance -) \ No newline at end of file +) + +### 13 - Remove unnecessary buttons from the modebar ---- +# [WARNING, NOT WORKING AT THIS POINT - WILL BREAK DASHBOARD IF UNCOMMENTED] + +# modebar_bttn_rmv <- list(config(displayModeBar = TRUE, +# modeBarButtonsToRemove = bttn_remove, +# displaylogo = F, editable = F)) From bb183bf48617b8e26175898749ebba5a2443fe52 Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Tue, 18 Jun 2024 18:17:42 +0100 Subject: [PATCH 15/75] Removed x-axis tick labels 'tickangle' attribute to make them reactive --- modules/indicators/E1_server.R | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/indicators/E1_server.R b/modules/indicators/E1_server.R index c9d05cf..9081046 100644 --- a/modules/indicators/E1_server.R +++ b/modules/indicators/E1_server.R @@ -100,7 +100,6 @@ output$E1_plot1 <- renderPlotly({ ), xaxis = list( - tickangle = -45, title = paste0(c("
", "Financial year", collapse = "")), # Don't think it's needed From 571a2e6f25cca7bacc6a067f01a24e60b10d3a0b Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Tue, 18 Jun 2024 18:22:24 +0100 Subject: [PATCH 16/75] Changed E1 legend string wrap width --- modules/indicators/E1_server.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/indicators/E1_server.R b/modules/indicators/E1_server.R index 9081046..7ce8129 100644 --- a/modules/indicators/E1_server.R +++ b/modules/indicators/E1_server.R @@ -64,7 +64,7 @@ output$E1_plot1 <- renderPlotly({ # width = 600, height = 300, line = list(width = 3), marker = list(size = 12), - name = ~str_wrap(area_name, 14)) %>% # legend labels + name = ~str_wrap(area_name, 19)) %>% # legend labels ### 7 - Graph title ---- From e3ee8630c0e34afe08f323539baae91f59869270 Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Wed, 19 Jun 2024 18:38:25 +0100 Subject: [PATCH 17/75] Adding tab text styling --- .gitignore | 3 --- www/stylesheet.css | 39 +++++++++++++++++++++++++++------------ 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 8f1c5bf..e3687c1 100644 --- a/.gitignore +++ b/.gitignore @@ -12,9 +12,6 @@ # Constants file constants.R -# Data prep script -data_preparation.R - # folders to ignrore data/ drafts/ diff --git a/www/stylesheet.css b/www/stylesheet.css index 71e7e27..3e736a3 100755 --- a/www/stylesheet.css +++ b/www/stylesheet.css @@ -1,6 +1,16 @@ /* MHQI Stylesheet */ /* Sheet has stopped working with phs styles variables for some reason...change to hex codes */ +/* [Page Navigation Buttons] */ +.navpageButton{ + background-color: #9B4393; /* button colour - phs-magenta */ + color: #ECEBF3; /* text colour --phs-purple-10*/ + border: 4px rounded ; + /*word-wrap: normal; /* tell css to wrap the text in buttons */ + /*white-space: normal; /* required for text wrapping to work */ + /*align: right;*/ +} + /* Main header*/ /*.main-header .navbar { background-color: #ECEBF3; /* Header colour */ @@ -14,6 +24,7 @@ h1 { font-weight: bold; } +/* [Dashboard Skin] */ /* dashboardHeader settings */ .skin-blue .main-header .logo { background-color: #3F3685; @@ -45,7 +56,9 @@ h1 { color: #655E9D; } -/* + +/* [ScotHub styling] */ + /* Defining shinydashboard 'box' element styling */ .box-header{ background-color: #ECEBF3; /* Header colour */ @@ -70,23 +83,25 @@ h1 { /*white-space: normal; /* required for text wrapping to work */ } -/* Define buttons styling */ -.navpageButton{ - background-color: #9B4393; /* button colour - phs-magenta */ - color: #ECEBF3; /* text colour --phs-purple-10*/ - border: 4px rounded ; - /*word-wrap: normal; /* tell css to wrap the text in buttons */ - /*white-space: normal; /* required for text wrapping to work */ - /*align: right;*/ -} -.titlePanel h2{ +/**//* Tab styling *//**/ + +/* Tab title */ +.container-fluid h2{ color: #3F3685; + font-size: 20px; font-weight: bold; } +/* Tab text */ +.col-sm-8 p{ + font-size: 14px; +} -/* Defining styling for tabs */ +.mainPanel h2{ + color: #3F3685; + font-weight: bold; +} .infographic{ width: 100%; padding: 10px; From f9d1a111624e6962c50a52371d63797ed23b9abf Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Wed, 19 Jun 2024 18:39:20 +0100 Subject: [PATCH 18/75] Added data prep file --- data_preparation.R | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 data_preparation.R diff --git a/data_preparation.R b/data_preparation.R new file mode 100644 index 0000000..48b41d5 --- /dev/null +++ b/data_preparation.R @@ -0,0 +1,11 @@ +## 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) + +unique_area_types <- E1_data %>% + distinct(area_type) %>% pull(area_type) \ No newline at end of file From 0b41b346a0ff2f8487822b39566c96c9891f0c25 Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Fri, 21 Jun 2024 19:23:14 +0100 Subject: [PATCH 19/75] Moved nav buttons fluidRow into mainPanel section to keep them at the bottom of pages --- modules/indicators/EF1_ui.R | 10 ++++++---- modules/indicators/EF2_ui.R | 6 +++--- modules/indicators/EF3_ui.R | 6 +++--- modules/indicators/EF4_ui.R | 6 +++--- modules/indicators/EF5_ui.R | 8 ++++---- modules/indicators/EQ1_ui.R | 6 +++--- modules/indicators/EQ2_ui.R | 7 ++++--- modules/indicators/EQ4_ui.R | 7 ++++--- modules/indicators/P1_ui.R | 6 +++--- modules/indicators/P2_ui.R | 6 +++--- modules/indicators/P3_ui.R | 6 +++--- modules/indicators/P4_ui.R | 4 ++-- modules/indicators/S1_ui.R | 6 +++--- modules/indicators/S2_ui.R | 4 ++-- modules/indicators/S5_ui.R | 4 ++-- modules/indicators/T1_ui.R | 4 ++-- modules/indicators/T2_ui.R | 8 +++----- modules/indicators/T3_ui.R | 10 ++++------ 18 files changed, 57 insertions(+), 57 deletions(-) diff --git a/modules/indicators/EF1_ui.R b/modules/indicators/EF1_ui.R index 69efbc5..1b29553 100644 --- a/modules/indicators/EF1_ui.R +++ b/modules/indicators/EF1_ui.R @@ -1,6 +1,7 @@ tabItem(tabName = "EF1_tab", fluidPage( titlePanel("EF1 - Rate of Emergency Bed Days for Adults"), + mainPanel( img(src='infographics/EF1.png', class = "infographic", @@ -17,8 +18,7 @@ tabItem(tabName = "EF1_tab", " using SMR04 data.", a(href="https://publichealthscotland.scot/services/data-management/data-management-in-secondary-care-hospital-activity/scottish-morbidity-records-smr/completeness/", "Data completeness"), - " for SMR04 was around 90% or better when the data was accessed.") - ), + " for SMR04 was around 90% or better when the data was accessed."), fluidRow( column(4, actionButton(inputId = "EF1_scot_hub_button", @@ -30,6 +30,8 @@ tabItem(tabName = "EF1_tab", column(4, actionButton(inputId = "EF2_nextButton", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) - ) - ) # End of fluidPage + ) + ) # End of mainPanel + ) # End of fluidPage + ) \ No newline at end of file diff --git a/modules/indicators/EF2_ui.R b/modules/indicators/EF2_ui.R index 131282a..64f809e 100644 --- a/modules/indicators/EF2_ui.R +++ b/modules/indicators/EF2_ui.R @@ -16,8 +16,7 @@ tabItem(tabName = "EF2_tab", " using SMR04 data.", a(href="https://publichealthscotland.scot/services/data-management/data-management-in-secondary-care-hospital-activity/scottish-morbidity-records-smr/completeness/", "Data completeness"), - " for SMR04 was around 90% or better when the data was accessed.") - ), + " for SMR04 was around 90% or better when the data was accessed."), fluidRow( column(4, actionButton(inputId = "EF2_scot_hub_button", @@ -30,6 +29,7 @@ tabItem(tabName = "EF2_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of fluidPage + ) # End of mainPanel + ) # End of fluidPage ) \ No newline at end of file diff --git a/modules/indicators/EF3_ui.R b/modules/indicators/EF3_ui.R index c543611..8759a8e 100644 --- a/modules/indicators/EF3_ui.R +++ b/modules/indicators/EF3_ui.R @@ -17,8 +17,7 @@ tabItem(tabName = "EF3_tab", "the Acute hospital activity and NHS beds information annual release publication, "), "and the denominator is sourced from ", a(href="https://www.publichealthscotland.scot/publications/resource-allocation-formula-nrac/resource-allocation-formula-nrac-for-nhsscotland-results-for-financial-year-2024-to-2025/", - "the National Resource Allocation publication.")) - ), + "the National Resource Allocation publication.")), fluidRow( column(4, actionButton(inputId = "EF3_scot_hub_button", @@ -31,6 +30,7 @@ tabItem(tabName = "EF3_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of fluidPage + ) # End of mainPanel + ) # End of fluidPage ) \ No newline at end of file diff --git a/modules/indicators/EF4_ui.R b/modules/indicators/EF4_ui.R index b56182f..dfd6f6a 100644 --- a/modules/indicators/EF4_ui.R +++ b/modules/indicators/EF4_ui.R @@ -15,8 +15,7 @@ tabItem(tabName = "EF4_tab", "excel workbook "), "which also includes data for organisations providing these services (14 territorial NHS Boards and the State Hospital at Carstairs Lanarkshire), as part of the ", a(href="https://publichealthscotland.scot/publications/scottish-health-service-costs/scottish-health-service-costs-high-level-costs-summary-2021-to-2022/", - "annual release of National Statistics covering expenditure in the financial year 2021/22.")) - ), + "annual release of National Statistics covering expenditure in the financial year 2021/22.")), fluidRow( column(4, actionButton(inputId = "EF4_scot_hub_button", @@ -29,6 +28,7 @@ tabItem(tabName = "EF4_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of fluidPage + ) # End of mainPanel + ) # End of fluidPage ) \ No newline at end of file diff --git a/modules/indicators/EF5_ui.R b/modules/indicators/EF5_ui.R index c119fc2..51f4562 100644 --- a/modules/indicators/EF5_ui.R +++ b/modules/indicators/EF5_ui.R @@ -10,8 +10,7 @@ tabItem(tabName = "EF5_tab", "services ranged from 8% to 19% for the quarter ending 30 ", "June 2023.")), br(), - p("The data for EF5 is sourced is sourced from health board returns, which may be incomplete.") - ), + p("The data for EF5 is sourced is sourced from health board returns, which may be incomplete."), fluidRow( @@ -25,5 +24,6 @@ tabItem(tabName = "EF5_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of fluidPage - ) \ No newline at end of file + ) # End of mainPanel + ) # End of fluidPage +) \ No newline at end of file diff --git a/modules/indicators/EQ1_ui.R b/modules/indicators/EQ1_ui.R index e5f2df4..ea4b757 100644 --- a/modules/indicators/EQ1_ui.R +++ b/modules/indicators/EQ1_ui.R @@ -13,8 +13,7 @@ tabItem(tabName = "EQ1_tab", br(), p("The data for EQ1 are sourced from SMR04 and death registrations ", a(href="https://www.nrscotland.gov.uk/statistics-and-data/statistics/statistics-by-theme/vital-events/deaths/deaths-background-information", - "(National Records of Scotland; NRS).")) - ), + "(National Records of Scotland; NRS).")), fluidRow( column(4, actionButton(inputId = "EQ1_scot_hub_button", @@ -27,5 +26,6 @@ tabItem(tabName = "EQ1_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of fluidPage + ) # End of mainPanel + ) # End of fluidPage ) diff --git a/modules/indicators/EQ2_ui.R b/modules/indicators/EQ2_ui.R index 711005e..88e5f88 100644 --- a/modules/indicators/EQ2_ui.R +++ b/modules/indicators/EQ2_ui.R @@ -11,8 +11,8 @@ tabItem(tabName = "EQ2_tab", br(), p("This data is sourced from the ", a(href="https://www.mwcscot.org.uk/publications?type=44&leg=54", - "Mental Welfare Commission.")) - ), + "Mental Welfare Commission.")), + fluidRow( column(4, actionButton(inputId = "EQ2_scot_hub_button", label = "Scotland Hub", icon = icon("home"), @@ -24,5 +24,6 @@ tabItem(tabName = "EQ2_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of fluidPage + ) # End of mainPanel + ) # End of fluidPage ) \ No newline at end of file diff --git a/modules/indicators/EQ4_ui.R b/modules/indicators/EQ4_ui.R index 9dbbf25..4e403ab 100644 --- a/modules/indicators/EQ4_ui.R +++ b/modules/indicators/EQ4_ui.R @@ -13,8 +13,8 @@ tabItem(tabName = "EQ4_tab", br(), p("The data for EQ4 is sourced from ", a(href="https://www.publichealthscotland.scot/services/discovery/#section-1-1", - "Discovery.")) - ), + "Discovery.")), + fluidRow( column(4, actionButton(inputId = "EQ2_prevButton", label = "Previous Page", icon = icon("arrow-left"), @@ -23,5 +23,6 @@ tabItem(tabName = "EQ4_tab", label = "Scotland Hub", icon = icon("home"), class = "navpageButton")) ) - ) # End of fluidPage + ) # End of mainPanel + ) # End of fluidPage ) \ No newline at end of file diff --git a/modules/indicators/P1_ui.R b/modules/indicators/P1_ui.R index f499d0d..0e2e471 100644 --- a/modules/indicators/P1_ui.R +++ b/modules/indicators/P1_ui.R @@ -14,8 +14,7 @@ tabItem(tabName = "P1_tab", p("Further information can be found in the ", a(href="https://www.gov.scot/collections/health-and-care-experience-survey/", "Health and Care Experience Survey"), - ".") - ), + "."), fluidRow( column(4, actionButton(inputId = "P1_scot_hub_button", @@ -28,5 +27,6 @@ tabItem(tabName = "P1_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of fluidPage + ) # End of mainPanel + ) # End of fluidPage ) \ No newline at end of file diff --git a/modules/indicators/P2_ui.R b/modules/indicators/P2_ui.R index d29808b..e140518 100644 --- a/modules/indicators/P2_ui.R +++ b/modules/indicators/P2_ui.R @@ -16,8 +16,7 @@ tabItem(tabName = "P2_tab", p("Further information can be found in the ", a(href="https://www.gov.scot/collections/health-and-care-experience-survey/", "Health and Care Experience Survey"), - ".") - ), + "."), fluidRow( column(4, actionButton(inputId = "P2_scot_hub_button", @@ -30,6 +29,7 @@ tabItem(tabName = "P2_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of fluidPage + ) # End of mainPanel + ) # End of fluidPage ) \ No newline at end of file diff --git a/modules/indicators/P3_ui.R b/modules/indicators/P3_ui.R index 92cf724..9cd5b6e 100644 --- a/modules/indicators/P3_ui.R +++ b/modules/indicators/P3_ui.R @@ -15,8 +15,7 @@ tabItem(tabName = "P3_tab", p("Further information can be found in the ", a(href="https://www.gov.scot/collections/health-and-care-experience-survey/", "Health and Care Experience Survey"), - ".") - ), + "."), # Navigation buttons fluidRow( @@ -30,5 +29,6 @@ tabItem(tabName = "P3_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of fluidPage + ) # End of mainPanel + ) # End of fluidPage ) \ No newline at end of file diff --git a/modules/indicators/P4_ui.R b/modules/indicators/P4_ui.R index 2af1342..75dcfd4 100644 --- a/modules/indicators/P4_ui.R +++ b/modules/indicators/P4_ui.R @@ -4,8 +4,7 @@ tabItem(tabName = "P4_tab", "registered per year with the Mental Welfare ", "Commission for Scotland")), mainPanel( - p("This indicator has not been updated since 2021.") - ), + p("This indicator has not been updated since 2021."), # Navigation buttons fluidRow( @@ -19,5 +18,6 @@ tabItem(tabName = "P4_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) + ) # End of mainPanel ) # End of fluidPage ) \ No newline at end of file diff --git a/modules/indicators/S1_ui.R b/modules/indicators/S1_ui.R index 29be37c..005667c 100644 --- a/modules/indicators/S1_ui.R +++ b/modules/indicators/S1_ui.R @@ -13,8 +13,7 @@ tabItem(tabName = "S1_tab", "Further information can be found in the [THIS LINK IS BROKEN]", a(href="https://www.scotpho.org.uk/health-wellbeing-and-disease/suicide/key-points/", "ScotPHO website"), - ".")) - ), + ".")), fluidRow( column(4, actionButton(inputId = "S1_scot_hub_button", @@ -27,5 +26,6 @@ tabItem(tabName = "S1_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) + ) # End of mainPanel + ) # End of fluidPage ) \ No newline at end of file diff --git a/modules/indicators/S2_ui.R b/modules/indicators/S2_ui.R index 7bbdc2a..27d1f85 100644 --- a/modules/indicators/S2_ui.R +++ b/modules/indicators/S2_ui.R @@ -18,8 +18,7 @@ tabItem(tabName = "S2_tab", p(paste0( "Board returns were received from NHS Ayrshire & Arran, NHS Borders, ", "NHS Fife, NHS Forth Valley, NHS Grampian, NHS Greater Glasgow ", - "& Clyde, NHS Highland, NHS Lothian, NHS Tayside, and NHS Western Isles.")) - ), + "& Clyde, NHS Highland, NHS Lothian, NHS Tayside, and NHS Western Isles.")), fluidRow( column(4, actionButton(inputId = "S2_scot_hub_button", @@ -32,5 +31,6 @@ tabItem(tabName = "S2_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) + ) # End of mainPanel ) # End of fluidPage ) # End of tabItem \ No newline at end of file diff --git a/modules/indicators/S5_ui.R b/modules/indicators/S5_ui.R index 585a528..b038762 100644 --- a/modules/indicators/S5_ui.R +++ b/modules/indicators/S5_ui.R @@ -19,8 +19,7 @@ tabItem(tabName = "S5_tab", "Board returns were received from NHS Ayrshire & Arran, NHS Borders, ", "NHS Fife, NHS Forth Valley, NHS Grampian, NHS Greater Glasgow ", "& Clyde, NHS Highland, NHS Lanarkshire, NHS Lothian, NHS Tayside, ", - "and NHS Western Isles.")) - ), + "and NHS Western Isles.")), fluidRow( column(4, actionButton(inputId = "S5_scot_hub_button", @@ -33,5 +32,6 @@ tabItem(tabName = "S5_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) + ) # End of mainPanel ) # End of fluidPage ) \ No newline at end of file diff --git a/modules/indicators/T1_ui.R b/modules/indicators/T1_ui.R index 8095731..4b47630 100644 --- a/modules/indicators/T1_ui.R +++ b/modules/indicators/T1_ui.R @@ -18,10 +18,10 @@ tabItem(tabName = "T1_tab", ".") ), fluidRow( - column(6, actionButton(inputId = "T1_scot_hub_button", + column(4, actionButton(inputId = "T1_scot_hub_button", label = "Scotland Hub", icon = icon("home"), class = "navpageButton")), - column(6, actionButton(inputId = "T2_nextButton", + column(4, actionButton(inputId = "T2_nextButton", label = "Next Page - T2", icon = icon("arrow-right"), class = "navpageButton")) ) diff --git a/modules/indicators/T2_ui.R b/modules/indicators/T2_ui.R index 28e2f07..7591c9d 100644 --- a/modules/indicators/T2_ui.R +++ b/modules/indicators/T2_ui.R @@ -18,9 +18,7 @@ tabItem(tabName = "T2_tab", p("Further information can be found in the ", a(href="https://publichealthscotland.scot/publications/child-and-adolescent-mental-health-services-camhs-waiting-times/", "Child and Adolescent Mental Health Services in Scotland: Waiting Times publication"), - ".") - ), - + "."), fluidRow( column(4, actionButton(inputId = "T2_scot_hub_button", label = "Scotland Hub", icon = icon("home"), @@ -31,7 +29,7 @@ tabItem(tabName = "T2_tab", column(4, actionButton(inputId = "T3_nextButton", label = "Next Page: T3", icon = icon("arrow-right"), class = "navpageButton")) - ) - + ) + ) # End of mainPanel ) # End of fluidPage ) \ No newline at end of file diff --git a/modules/indicators/T3_ui.R b/modules/indicators/T3_ui.R index c060c17..3a614e9 100644 --- a/modules/indicators/T3_ui.R +++ b/modules/indicators/T3_ui.R @@ -26,10 +26,8 @@ tabItem(tabName = "T3_tab", p("Further information can be found in the ", a(href="https://beta.isdscotland.org/find-publications-and-data/lifestyle-and-behaviours/substance-use/national-drug-and-alcohol-treatment-waiting-times/", "National Drug and Alcohol Treatment Waiting Times publication"), - ".") - ), - - fluidRow( + "."), + fluidRow( column(4, actionButton(inputId = "T3_scot_hub_button", label = "Scotland Hub", icon = icon("home"), class = "navpageButton")), @@ -39,7 +37,7 @@ tabItem(tabName = "T3_tab", column(4, actionButton(inputId = "S1_nextButton", label = "Next Page: S1", icon = icon("arrow-right"), class = "navpageButton")) - ) - + ) + ) # End of mainPanel ) # End of fluidPage ) \ No newline at end of file From 7864e36182497e3d3531322647f4b234652ad9e2 Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Thu, 27 Jun 2024 17:26:46 +0100 Subject: [PATCH 20/75] Applying fix for indicator content spacing --- app.R | 8 +++----- www/stylesheet.css | 5 +++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app.R b/app.R index 3cf0d9e..39cf654 100644 --- a/app.R +++ b/app.R @@ -1,4 +1,4 @@ -# Loading packages test +# Loading packages library(phsstyles) library(plotly) @@ -10,9 +10,6 @@ library(shinydashboard) library(fresh) # for customising shinydashboard look library(shinyWidgets) - - - # Data import section ---------------------------------------------------- # Source constants used throughout app @@ -97,7 +94,8 @@ server <- function(input, output, session) { # Navigation buttons ---- source("modules/nav_buttons_server.R", local = TRUE) source("modules/indicators/E1_server.R", local = TRUE) - # Keep dashboard active indefinnitely to meet accessibility requirements + + # Keep dashboard active indefinitely to meet accessibility requirements # (Keep at the end of server) auto_invalidate <- reactiveTimer(10000) observe({ diff --git a/www/stylesheet.css b/www/stylesheet.css index 3e736a3..b6241fa 100755 --- a/www/stylesheet.css +++ b/www/stylesheet.css @@ -93,6 +93,11 @@ h1 { font-weight: bold; } +/* Tab content under title */ +.col-sm-8{ + width: auto; +} + /* Tab text */ .col-sm-8 p{ font-size: 14px; From a92d511f604563a1e7e49924d9df4684cdd06646 Mon Sep 17 00:00:00 2001 From: Alex Bruce <74981565+alex-bruce@users.noreply.github.com> Date: Fri, 28 Jun 2024 17:39:51 +0100 Subject: [PATCH 21/75] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 40bab25..4144e98 100644 --- a/README.md +++ b/README.md @@ -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. + From 9161aaad551ade8c1298a16b4968fd04396d07be Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Fri, 12 Jul 2024 17:33:10 +0100 Subject: [PATCH 22/75] Minor grammar fix in intro --- modules/introduction_ui.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/introduction_ui.R b/modules/introduction_ui.R index f070b12..1ff0837 100644 --- a/modules/introduction_ui.R +++ b/modules/introduction_ui.R @@ -2,7 +2,7 @@ tabItem(tabName = "intro", fluidPage( # titlePanel("Mental Health Quality Indicators Joint Collection Materials"), mainPanel( - h1("Welcome, to the Mental Health Quality Indicators Dashboard"), + h1("Welcome to the Mental Health Quality Indicators Dashboard"), p("This dashbaord covers 19 indicators out of the 32 indicators set out in the "), p("3 of the indicators have been developed into interactive formats From 1e3ee4dc7d9a2d4f16657c363df6bfe2fa31d1c6 Mon Sep 17 00:00:00 2001 From: MahriScot Date: Mon, 22 Jul 2024 13:51:25 +0100 Subject: [PATCH 23/75] 2nd graph added for E1 Additional code added to: * app.R (added tidyverse library) * data_preperation.R (added distinct financial years for graph) * E1_server.R * E1_ui.R --- app.R | 1 + data_preparation.R | 7 ++- modules/indicators/E1_server.R | 89 ++++++++++++++++++++++++++++++++++ modules/indicators/E1_ui.R | 24 +++++++++ 4 files changed, 120 insertions(+), 1 deletion(-) diff --git a/app.R b/app.R index 39cf654..1ad46d3 100644 --- a/app.R +++ b/app.R @@ -9,6 +9,7 @@ library(shiny) library(shinydashboard) library(fresh) # for customising shinydashboard look library(shinyWidgets) +library(tidyverse) # added by mahri for fct_reorder() in graph # Data import section ---------------------------------------------------- diff --git a/data_preparation.R b/data_preparation.R index 48b41d5..29cf8ad 100644 --- a/data_preparation.R +++ b/data_preparation.R @@ -8,4 +8,9 @@ E1_data <- read.csv("data/E1.csv") %>% fyear = financial_year) unique_area_types <- E1_data %>% - distinct(area_type) %>% pull(area_type) \ No newline at end of file + distinct(area_type) %>% pull(area_type) + +# For E1 plot 2: +unique_fyear <- E1_data %>% + distinct(fyear) %>% + pull(fyear) diff --git a/modules/indicators/E1_server.R b/modules/indicators/E1_server.R index 7ce8129..526366b 100644 --- a/modules/indicators/E1_server.R +++ b/modules/indicators/E1_server.R @@ -1,3 +1,5 @@ +# PLOT 1 (MS added title) ---- + output$E1_plot1_areaType_output <- renderUI({ shinyWidgets::pickerInput( "E1_plot1_areaType", @@ -144,3 +146,90 @@ output$E1_plot1 <- renderPlotly({ # "Area of Residence", # "Number of Bed Days")) # }) + + + + + + + + +# PLOT 2 (MS added all) ---- + +## Picker for user selecting Financial Year ---- + +output$E1_plot2_year_output <- renderUI({ + shinyWidgets::pickerInput( + "E1_plot2_year", + label = "Select financial year:", + choices = unique_fyear, + selected = "2022/23") +}) + +## Selecting appropriate data for graph ---- + +E1_plot2_Data <- reactive({ + E1_data %>% + select(fyear, area_type, area_name, dd_bed_days, rate_per_1000_population) %>% + filter(area_type == "Health board") %>% + filter(fyear == input$E1_plot2_year) %>% + mutate(area_name = fct_reorder(area_name, rate_per_1000_population)) %>% # for ordering by most to least bed days + mutate(to_highlight = if_else(area_name == "NHS Scotland", # for highlighting NHS Scotland + "seagreen", "#0080FF")) # changed from "yes" and "no" so that these colours appear on the graph and don't have a legend using "marker = list(color... )" +}) # only using "seagreen" to make sure it is working for now + + + +## Create the discharges bar chart. ---- + +output$E1_plot2 <- renderPlotly({ + + ### Hover Text - Tooltip creation (doesn't quite work) ---- + + tooltip_E1_plot2 <- paste0("Area of residence: ", + E1_plot2_Data()$area_name, + "
", + "Number of Bed Days per 1000 population: ", + E1_plot2_Data()$dd_bed_days) + + ### Create the main body of the chart ---- + + plot_ly(data = E1_plot2_Data(), + # Select your variables. + + x = ~rate_per_1000_population, + y = ~area_name, + # fill = ~to_highlight, # highlighting Scotland but this is working with color and colors below + marker = list(color = ~to_highlight), # This stops the colour legend appearing on the hover. Using color= and colors= below adds the legend + # color = ~to_highlight, + # colors = c("#0080FF", "seagreen"), # line colour - Dark blue for all lines. seagreen for test + #text = tooltip_E1_plot2, # This and hoverinfo = "text" were showing the info when hovering AND permanently on the graph + # hoverinfo = "text", + hoverinfo = tooltip_E1_plot2, + type = 'bar', orientation = 'h') %>% + + + + ### Graph titles ----- + + layout( + title = paste0("", + "Delayed Discharge Bed Days for the Financial Year: ", input$E1_plot2_year, + "
", + "
"), + # title = list(standoff = 1), # tried lots of ways of doing this but nothing working + #title = list(size = 12, y = 5, x = 0, xanchor = 'center', yanchor = 'top'), # none of this does anything to change things (no variation of any of them) + + separators = ".", + + yaxis = list(title =""), + + xaxis = list(title = "Number of Days", + dtick = 10, # shows a marker for every 10th number of bed days + range = list(0, 80)), # ensures all graphs have the same range of 0- 80 days (make sure this is extended if needed, it's going up each year) + + font = list(size = 12), + + showlegend = FALSE) + +}) \ No newline at end of file diff --git a/modules/indicators/E1_ui.R b/modules/indicators/E1_ui.R index 2ccd172..9fc6fb8 100644 --- a/modules/indicators/E1_ui.R +++ b/modules/indicators/E1_ui.R @@ -23,6 +23,30 @@ tabItem(tabName = "E1_tab", br(), br(), + + tags$p("Below is a graph showing a comparison between health boards and NHS Scotland for your selected financial year."), + # br(), + # tags$p(paste0("Below is a graph showing a comparison between health boards for year "), E1_plot2_year_output), # MS: this is wrong + + fluidRow( + column(6,uiOutput("E1_plot2_year_output")) + ), + + fluidRow( + plotlyOutput("E1_plot2" + # , + # width = "100%", + # height = "50%" + ) + ), + br(), + tags$p("Source: Delayed discharges in NHS Scotland annual publication", + br(), + "For ages 18 years and above"), + # as copied from above -- dataTableOutput("diagnoses_table"), + br(), + br(), + go_2_top_bttn, # tags$a(href = '#E1_top', From 21e66f365fe24866f542dedfbd4996afc3313cb7 Mon Sep 17 00:00:00 2001 From: MahriScot Date: Mon, 22 Jul 2024 15:01:12 +0100 Subject: [PATCH 24/75] added archive/ --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index e3687c1..caafb14 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ constants.R data/ drafts/ www/infographics +archive/ # Common text files that may contain data # *.[cC][sS][vV] From 0162b08988442c285c6f12053af2a656e14aad7e Mon Sep 17 00:00:00 2001 From: MahriScot Date: Thu, 25 Jul 2024 12:46:10 +0100 Subject: [PATCH 25/75] E1 graph - added margin/padding around axis and graph's title. Also added same code as for graph 1 that removes unnecessary buttons from modebar --- modules/indicators/E1_server.R | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/indicators/E1_server.R b/modules/indicators/E1_server.R index 526366b..dc2b9a4 100644 --- a/modules/indicators/E1_server.R +++ b/modules/indicators/E1_server.R @@ -206,13 +206,16 @@ output$E1_plot2 <- renderPlotly({ #text = tooltip_E1_plot2, # This and hoverinfo = "text" were showing the info when hovering AND permanently on the graph # hoverinfo = "text", hoverinfo = tooltip_E1_plot2, - type = 'bar', orientation = 'h') %>% + type = 'bar', + orientation = 'h') %>% - ### Graph titles ----- + ### Graph layout and titles ----- layout( + margin = list(l=0, r=20, b=25, t=50, pad=3), # i only see a difference in the top and the padding, but this adds space around title, axis titles, padding is around graph itself (between axis and values) ("left, right, bottom, top, padding") + title = paste0("", "Delayed Discharge Bed Days for the Financial Year: ", input$E1_plot2_year, "
", @@ -230,6 +233,12 @@ output$E1_plot2 <- renderPlotly({ font = list(size = 12), - showlegend = FALSE) + showlegend = FALSE) %>% + + ### Remove unnecessary buttons from the modebar ---- + + config(displayModeBar = TRUE, + modeBarButtonsToRemove = bttn_remove, + displaylogo = F, editable = F) }) \ No newline at end of file From 0dd69c4e09342fcddf94c6ff8b8b0402b7a4ca88 Mon Sep 17 00:00:00 2001 From: Cormac-Murray Date: Mon, 29 Jul 2024 11:57:43 +0100 Subject: [PATCH 26/75] EQ1 graph and server updates --- app.R | 3 + data_preparation.R | 7 ++ modules/indicators/EQ1_server.R | 157 ++++++++++++++++++++++++++++++++ modules/indicators/EQ1_ui.R | 53 ++++++++--- 4 files changed, 207 insertions(+), 13 deletions(-) create mode 100644 modules/indicators/EQ1_server.R diff --git a/app.R b/app.R index 1ad46d3..0208dc7 100644 --- a/app.R +++ b/app.R @@ -94,7 +94,10 @@ server <- function(input, output, session) { # 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) # Keep dashboard active indefinitely to meet accessibility requirements # (Keep at the end of server) diff --git a/data_preparation.R b/data_preparation.R index 29cf8ad..1d238ba 100644 --- a/data_preparation.R +++ b/data_preparation.R @@ -14,3 +14,10 @@ unique_area_types <- E1_data %>% unique_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) + diff --git a/modules/indicators/EQ1_server.R b/modules/indicators/EQ1_server.R new file mode 100644 index 0000000..c696eac --- /dev/null +++ b/modules/indicators/EQ1_server.R @@ -0,0 +1,157 @@ +# PLOT 1 (MS added title) ---- + +output$EQ1_plot1_areaType_output <- renderUI({ + shinyWidgets::pickerInput( + "EQ1_plot1_areaType", + label = "Select type of geography:", + choices = unique_area_types, + selected = "Health board") +}) + +output$EQ1_plot1_areaName_output <- renderUI({ + shinyWidgets::pickerInput( + "EQ1_plot1_areaName", + label = "Select area(s) (Maximum 5):", + choices = sort(unique(as.character( + EQ1_data$area_name + [EQ1_data$area_type %in% input$EQ1_plot1_areaType] + ))) + , + multiple = TRUE, + options = list("max-options" = 5, + `selected-text-format` = "count > 1") + ) +}) + +EQ1_plot1_Data <- reactive({ + EQ1_data %>% + select(Year, area_type, area_name, RiskRatio, SMR04_Pop_Rate, General_Pop_Rate) %>% + filter(area_type %in% input$EQ1_plot1_areaType + & area_name %in% input$EQ1_plot1_areaName) +}) + +# Create the discharges line chart. + +output$EQ1_plot1 <- renderPlotly({ +# +# # # No data plot +# # if(sum(E1_plot1_Data()$dd_bed_days) == 0 & +# # !is.na(sum(E1_plot1_Data()$dd_bed_days))) +# # +# # { +# # noDataPlot(phs_colours("phs-purple")) +# # } +# # +# # else { +# + ### 3 - Tooltip creation ---- + + tooltip_EQ1 <- paste0("Financial year: ", + EQ1_plot1_Data()$Year, + "
", + "Area of residence: ", + EQ1_plot1_Data()$area_name, + "
", + "Mortality rate: ", + EQ1_plot1_Data()$RiskRatio) + + ### 4 - Create the main body of the chart ---- + + plot_ly(data = EQ1_plot1_Data(), + # Select your variables. + x = ~Year, y = ~RiskRatio, color = ~area_name, + colors = c("#0080FF"), # line colour - Dark blue for all lines + text = tooltip_EQ1, hoverinfo = "text", + type = 'scatter', mode = 'lines+markers', + # width = 600, height = 300, + line = list(width = 3), + marker = list(size = 12), + name = ~str_wrap(area_name, 19)) %>% # legend labels + + ### 7 - Graph title ---- + + # Make the graph title reactive. + + layout(title = + paste0( + "", + "Mortality rate for persons in contact with MH services", + "
", + " by ", input$EQ1_plot1_areaType, ", ", first(as.vector(EQ1_plot1_Data()$Year)), + " to ", + last(as.vector(EQ1_plot1_Data()$Year)), + "
", + "
" + ), + + separators = ".", + + yaxis = list( + exponentformat = "none", + separatethousands = TRUE, + range = c(0, max(EQ1_plot1_Data()$RiskRatio, na.rm = TRUE) + + (max(EQ1_plot1_Data()$RiskRatio, na.rm = TRUE)*0.1) + ), + title = paste0(c(rep(" ", 20), + input$EQ1_1_input_1, + rep(" ", 20), + rep("\n ", 3))), + showline = TRUE, + ticks = "outside" + ), + + xaxis = list( + title = paste0(c("
", + "Calendar year", + collapse = "")), # Don't think it's needed + showline = TRUE, + ticks = "outside" + ), + + margin = list(l = 90, r = 60, b = 180, t = 120), + title = list(size = 15), + font = list(size = 13), + # Legend + showlegend = TRUE, + legend = list(x = 1, + y = 1, + bgcolor = 'rgba(255, 255, 255, 0)', + bordercolor = 'rgba(255, 255, 255, 0)') + # legend = list(orientation = "h", # show entries horizontally + # xanchor = "center", # use center of legend as anchor + # x = 0.5, y = -0.9) # put legend in center of x-axis + ) %>% + + ### 13 - Remove unnecessary buttons from the modebar ---- + + config(displayModeBar = TRUE, + modeBarButtonsToRemove = bttn_remove, + displaylogo = F, editable = F) + + # } + +}) + + +### 15 - Table below graph creation ---- + +# output$E1_1_trend_table <- renderDataTable({ +# datatable(E1_plot1_Data(), +# style = 'bootstrap', +# class = 'table-bordered table-condensed', +# rownames = FALSE, +# options = list(pageLength = 16, autoWidth = TRUE, dom = 'tip'), +# colnames = c("Financial year", +# "Area of Residence", +# "Number of Bed Days")) +# }) + + + + + + + + + + diff --git a/modules/indicators/EQ1_ui.R b/modules/indicators/EQ1_ui.R index ea4b757..44633dd 100644 --- a/modules/indicators/EQ1_ui.R +++ b/modules/indicators/EQ1_ui.R @@ -1,20 +1,46 @@ tabItem(tabName = "EQ1_tab", fluidPage( - titlePanel("EQ1 - Premature mortality rate = Standardised mortality rate for persons in contact with mental health services"), + titlePanel(paste0( + "EQ1 - Premature mortality rate = Standardised mortality rate ", + "for persons in contact with mental health services")), mainPanel( - img(src='infographics/EQ1.png', - class = "infographic", - alt = paste0( - "The mortality rate for persons in contact with the mental ", - "health service in Scotland is 2.71 times higher than the ", - "mortality rate for the general population when ", - "standardised by age and sex in 2021/22. This compares ", - "with 2.62 in 2020/21.")), + tags$p("Below is a graph showing the changes over time."), + + fluidRow( + column(6,uiOutput("EQ1_plot1_areaType_output")), + column(6,uiOutput("EQ1_plot1_areaName_output")) + ), + + fluidRow( + plotlyOutput("EQ1_plot1" + # , + # width = "100%", + # height = "50%" + ) + ), + br(), + # dataTableOutput("diagnoses_table"), + br(), + br(), + + + + br(), + + go_2_top_bttn, + + # tags$a(href = '#E1_top', + # icon("circle-arrow-up", + # lib = "glyphicon"), + # "Back to top"), + br(), br(), - p("The data for EQ1 are sourced from SMR04 and death registrations ", - a(href="https://www.nrscotland.gov.uk/statistics-and-data/statistics/statistics-by-theme/vital-events/deaths/deaths-background-information", - "(National Records of Scotland; NRS).")), - + # ), # End of mainPanel + + + + + fluidRow( column(4, actionButton(inputId = "EQ1_scot_hub_button", label = "Scotland Hub", icon = icon("home"), @@ -29,3 +55,4 @@ tabItem(tabName = "EQ1_tab", ) # End of mainPanel ) # End of fluidPage ) + From fb46e519fbd1133bbe8c8f4a030acb2134d24b9a Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Mon, 29 Jul 2024 16:32:28 +0100 Subject: [PATCH 27/75] Outlining indicator alt text method --- indicator_alt_text.R | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 indicator_alt_text.R diff --git a/indicator_alt_text.R b/indicator_alt_text.R new file mode 100644 index 0000000..e5baf0b --- /dev/null +++ b/indicator_alt_text.R @@ -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)) \ No newline at end of file From a232c15caa6b33c9d73d83c6af086b6996bc32b6 Mon Sep 17 00:00:00 2001 From: MahriScot Date: Tue, 30 Jul 2024 13:13:22 +0100 Subject: [PATCH 28/75] E1 2nd graph - xasis changes. I wanted the axis range to be "0:whatever the highest value is across ALL years" for every year's graph. Things I tried, that didn't work, included: # rangemode = "tozero" # tick0 = 0 # range = list(c(0, 300), round(max(E1_data$rate_per_1000_population), 10)) ----- this one ensures all graphs have the same range of 0-300 days but the graph wasn't starting at 0 (As bed days are going up each year, "round(...,10)" sets the xaxis as 10 more than whatever the new data shows as the maximum value) --- modules/indicators/E1_server.R | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/indicators/E1_server.R b/modules/indicators/E1_server.R index dc2b9a4..76a114d 100644 --- a/modules/indicators/E1_server.R +++ b/modules/indicators/E1_server.R @@ -227,9 +227,17 @@ output$E1_plot2 <- renderPlotly({ yaxis = list(title =""), + # Re: xasis, I wanted the axis range to be "0:whatever the highest value is across ALL + # years" for every year's graph. Things I tried, that didn't work, included: + # rangemode = "tozero" + # tick0 = 0 + # range = list(c(0, 300), round(max(E1_data$rate_per_1000_population), 10)), # ensures all graphs have the same range of 0-300 days but the graph wasn't starting at 0 (As bed days are going up each year, "round(...,10)" sets the xaxis as 10 more than whatever the new data shows as the maximum value) xaxis = list(title = "Number of Days", - dtick = 10, # shows a marker for every 10th number of bed days - range = list(0, 80)), # ensures all graphs have the same range of 0- 80 days (make sure this is extended if needed, it's going up each year) + dtick = 10, # shows a marker for every 10th number of bed days + # range = c(~min(c(-1, E1_data$rate_per_1000_population)), ~max(c(1, E1_data$rate_per_1000_population))), # I can't work out why this might be better when the below works too + range = c(~min(0), ~max(c(1, E1_data$rate_per_1000_population))), + autorange = FALSE), # if it were TRUE then the range would change for each graph + font = list(size = 12), From 0241130bc1f9024c4d72d977e2dc32ef053247a5 Mon Sep 17 00:00:00 2001 From: Cormac-Murray Date: Fri, 2 Aug 2024 13:13:18 +0100 Subject: [PATCH 29/75] EQ1 Chart Updates --- modules/indicators/EQ1_server.R | 326 +++++++++++++++++++++++++++++++- modules/indicators/EQ1_ui.R | 26 ++- 2 files changed, 347 insertions(+), 5 deletions(-) diff --git a/modules/indicators/EQ1_server.R b/modules/indicators/EQ1_server.R index c696eac..bfe4fd1 100644 --- a/modules/indicators/EQ1_server.R +++ b/modules/indicators/EQ1_server.R @@ -11,14 +11,14 @@ output$EQ1_plot1_areaType_output <- renderUI({ output$EQ1_plot1_areaName_output <- renderUI({ shinyWidgets::pickerInput( "EQ1_plot1_areaName", - label = "Select area(s) (Maximum 5):", + label = "Select area(s) (Maximum 4):", choices = sort(unique(as.character( EQ1_data$area_name [EQ1_data$area_type %in% input$EQ1_plot1_areaType] ))) , multiple = TRUE, - options = list("max-options" = 5, + options = list("max-options" = 4, `selected-text-format` = "count > 1") ) }) @@ -30,7 +30,7 @@ EQ1_plot1_Data <- reactive({ & area_name %in% input$EQ1_plot1_areaName) }) -# Create the discharges line chart. +# Create the risk ratios line chart. output$EQ1_plot1 <- renderPlotly({ # @@ -60,11 +60,16 @@ output$EQ1_plot1 <- renderPlotly({ plot_ly(data = EQ1_plot1_Data(), # Select your variables. x = ~Year, y = ~RiskRatio, color = ~area_name, - colors = c("#0080FF"), # line colour - Dark blue for all lines + colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), text = tooltip_EQ1, hoverinfo = "text", type = 'scatter', mode = 'lines+markers', # width = 600, height = 300, line = list(width = 3), + linetype = ~area_name, + linetypes = c("solid", "dot"), + # Select symbols for the health boards, and set their size. + symbol = ~area_name, + symbols = c("circle", "triangle-up", "circle", "triangle-up"), marker = list(size = 12), name = ~str_wrap(area_name, 19)) %>% # legend labels @@ -133,6 +138,319 @@ output$EQ1_plot1 <- renderPlotly({ }) + + +####### Create the SMR04 rates bar chart. + +output$EQ1_plot2 <- renderPlotly({ + # + # # # No data plot + # # if(sum(E1_plot1_Data()$dd_bed_days) == 0 & + # # !is.na(sum(E1_plot1_Data()$dd_bed_days))) + # # + # # { + # # noDataPlot(phs_colours("phs-purple")) + # # } + # # + # # else { + # + ### 3 - Tooltip creation ---- + + tooltip_EQ1_2 <- paste0("Financial year: ", + EQ1_plot1_Data()$Year, + "
", + "Area of residence: ", + EQ1_plot1_Data()$area_name, + "
", + "Mortality rate: ", + EQ1_plot1_Data()$SMR04_Pop_Rate) + + ### 4 - Create the main body of the chart ---- + + plot_ly(data = EQ1_plot1_Data(), + # Select your variables. + x = ~Year, y = ~SMR04_Pop_Rate, type = 'bar', color = ~area_name, + #add_trace(p = data, y = ~General_Pop_Rate), + colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), + text = tooltip_EQ1_2, hoverinfo = "text", + marker = list(size = 12), + name = ~str_wrap(area_name, 19)) %>% # legend labels + + ### 7 - Graph title ---- + + # Make the graph title reactive. + + layout(title = + paste0( + "", + "Mortality rate for persons in contact with MH services", + "
", + " by ", input$EQ1_plot1_areaType, ", ", first(as.vector(EQ1_plot1_Data()$Year)), + " to ", + last(as.vector(EQ1_plot1_Data()$Year)), + "
", + "
" + ), + + separators = ".", + + yaxis = list( + exponentformat = "none", + separatethousands = TRUE, + range = c(0, max(EQ1_plot1_Data()$SMR04_Pop_Rate, na.rm = TRUE) + + (max(EQ1_plot1_Data()$SMR04_Pop_Rate, na.rm = TRUE)*0.1) + ), + title = paste0(c(rep(" ", 20), + input$EQ1_1_input_1, + rep(" ", 20), + rep("\n ", 3))), + showline = TRUE, + ticks = "outside" + ), + + xaxis = list( + title = paste0(c("
", + "Area name", + collapse = "")), # Don't think it's needed + showline = TRUE, + ticks = "outside" + ), + + margin = list(l = 90, r = 60, b = 180, t = 120), + title = list(size = 15), + font = list(size = 13), + # Legend + showlegend = TRUE, + legend = list(x = 1, + y = 1, + bgcolor = 'rgba(255, 255, 255, 0)', + bordercolor = 'rgba(255, 255, 255, 0)') + # legend = list(orientation = "h", # show entries horizontally + # xanchor = "center", # use center of legend as anchor + # x = 0.5, y = -0.9) # put legend in center of x-axis + ) %>% + + ### 13 - Remove unnecessary buttons from the modebar ---- + + config(displayModeBar = TRUE, + modeBarButtonsToRemove = bttn_remove, + displaylogo = F, editable = F) + + # } + +}) + + + + +####### Create the general population rates bar chart. + +output$EQ1_plot3 <- renderPlotly({ + # + # # # No data plot + # # if(sum(E1_plot1_Data()$dd_bed_days) == 0 & + # # !is.na(sum(E1_plot1_Data()$dd_bed_days))) + # # + # # { + # # noDataPlot(phs_colours("phs-purple")) + # # } + # # + # # else { + # + ### 3 - Tooltip creation ---- + + tooltip_EQ1_3 <- paste0("Financial year: ", + EQ1_plot1_Data()$Year, + "
", + "Area of residence: ", + EQ1_plot1_Data()$area_name, + "
", + "Mortality rate: ", + EQ1_plot1_Data()$General_Pop_Rate) + + ### 4 - Create the main body of the chart ---- + + plot_ly(data = EQ1_plot1_Data(), + # Select your variables. + x = ~Year, y = ~General_Pop_Rate, type = 'bar', color = ~area_name, + #add_trace(p = data, y = ~General_Pop_Rate), + colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), + text = tooltip_EQ1_3, hoverinfo = "text", + marker = list(size = 12), + name = ~str_wrap(area_name, 19)) %>% # legend labels + + ### 7 - Graph title ---- + + # Make the graph title reactive. + + layout(title = + paste0( + "", + "Mortality rate for the general population", + "
", + " by ", input$EQ1_plot1_areaType, ", ", first(as.vector(EQ1_plot1_Data()$Year)), + " to ", + last(as.vector(EQ1_plot1_Data()$Year)), + "
", + "
" + ), + + separators = ".", + + yaxis = list( + exponentformat = "none", + separatethousands = TRUE, + range = c(0, max(EQ1_plot1_Data()$General_Pop_Rate, na.rm = TRUE) + + (max(EQ1_plot1_Data()$General_Pop_Rate, na.rm = TRUE)*0.1) + ), + title = paste0(c(rep(" ", 20), + input$EQ1_1_input_1, + rep(" ", 20), + rep("\n ", 3))), + showline = TRUE, + ticks = "outside" + ), + + xaxis = list( + title = paste0(c("
", + "Area name", + collapse = "")), # Don't think it's needed + showline = TRUE, + ticks = "outside" + ), + + margin = list(l = 90, r = 60, b = 180, t = 120), + title = list(size = 15), + font = list(size = 13), + # Legend + showlegend = TRUE, + legend = list(x = 1, + y = 1, + bgcolor = 'rgba(255, 255, 255, 0)', + bordercolor = 'rgba(255, 255, 255, 0)') + # legend = list(orientation = "h", # show entries horizontally + # xanchor = "center", # use center of legend as anchor + # x = 0.5, y = -0.9) # put legend in center of x-axis + ) %>% + + ### 13 - Remove unnecessary buttons from the modebar ---- + + config(displayModeBar = TRUE, + modeBarButtonsToRemove = bttn_remove, + displaylogo = F, editable = F) + + # } + +}) + + + + + +####### Create the combined general population and MH rates bar chart. +# +# output$EQ1_plot4 <- renderPlotly({ +# # +# # # # No data plot +# # # if(sum(E1_plot1_Data()$dd_bed_days) == 0 & +# # # !is.na(sum(E1_plot1_Data()$dd_bed_days))) +# # # +# # # { +# # # noDataPlot(phs_colours("phs-purple")) +# # # } +# # # +# # # else { +# # +# ### 3 - Tooltip creation ---- +# +# tooltip_EQ1_4 <- paste0("Financial year: ", +# EQ1_plot1_Data()$Year, +# "
", +# "Area of residence: ", +# EQ1_plot1_Data()$area_name, +# "
", +# "MH population rate: ", +# EQ1_plot1_Data()$SMR04_Pop_Rate, +# "
", +# "General population rate: ", +# EQ1_plot1_Data()$General_Pop_Rate) +# +# ### 4 - Create the main body of the chart ---- +# +# plot_ly(data = EQ1_plot1_Data(), +# # Select your variables. +# x = ~Year, y = ~SMR04_Pop_Rate, type = 'bar', color = ~area_name, +# add_trace(y = ~General_Pop_Rate), +# colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), +# text = tooltip_EQ1_4, hoverinfo = "text", +# marker = list(size = 12), +# name = ~str_wrap(area_name, 19)) %>% # legend labels +# +# ### 7 - Graph title ---- +# +# # Make the graph title reactive. +# +# layout(title = +# paste0( +# "", +# "Mortality rates for the MH and general population", +# "
", +# " by ", input$EQ1_plot1_areaType, ", ", first(as.vector(EQ1_plot1_Data()$Year)), +# " to ", +# last(as.vector(EQ1_plot1_Data()$Year)), +# "
", +# "
" +# ), +# +# separators = ".", +# +# yaxis = list( +# exponentformat = "none", +# separatethousands = TRUE, +# range = c(0, max(EQ1_plot1_Data()$General_Pop_Rate, na.rm = TRUE) +# + (max(EQ1_plot1_Data()$General_Pop_Rate, na.rm = TRUE)*0.1) +# ), +# title = paste0(c(rep(" ", 20), +# input$EQ1_1_input_1, +# rep(" ", 20), +# rep("\n ", 3))), +# showline = TRUE, +# ticks = "outside" +# ), +# +# xaxis = list( +# title = paste0(c("
", +# "Area name", +# collapse = "")), # Don't think it's needed +# showline = TRUE, +# ticks = "outside" +# ), +# +# margin = list(l = 90, r = 60, b = 180, t = 120), +# title = list(size = 15), +# font = list(size = 13), +# # Legend +# showlegend = TRUE, +# legend = list(x = 1, +# y = 1, +# bgcolor = 'rgba(255, 255, 255, 0)', +# bordercolor = 'rgba(255, 255, 255, 0)') +# # legend = list(orientation = "h", # show entries horizontally +# # xanchor = "center", # use center of legend as anchor +# # x = 0.5, y = -0.9) # put legend in center of x-axis +# ) %>% +# +# ### 13 - Remove unnecessary buttons from the modebar ---- +# +# config(displayModeBar = TRUE, +# modeBarButtonsToRemove = bttn_remove, +# displaylogo = F, editable = F) +# +# # } +# +# }) + + ### 15 - Table below graph creation ---- # output$E1_1_trend_table <- renderDataTable({ diff --git a/modules/indicators/EQ1_ui.R b/modules/indicators/EQ1_ui.R index 44633dd..00b3a87 100644 --- a/modules/indicators/EQ1_ui.R +++ b/modules/indicators/EQ1_ui.R @@ -19,8 +19,32 @@ tabItem(tabName = "EQ1_tab", ) ), br(), - # dataTableOutput("diagnoses_table"), br(), + fluidRow( + plotlyOutput("EQ1_plot2" + # , + # width = "100%", + # height = "50%" + ) + ), + br(), + br(), + fluidRow( + plotlyOutput("EQ1_plot3" + # , + # width = "100%", + # height = "50%" + ) + ), + br(), + br(), + fluidRow( + plotlyOutput("EQ1_plot4" + # , + # width = "100%", + # height = "50%" + ) + ), br(), From 731eb051b6852a666947e917efa7e413ed5fefc2 Mon Sep 17 00:00:00 2001 From: MahriScot Date: Thu, 8 Aug 2024 12:38:59 +0100 Subject: [PATCH 30/75] changing filter names so they include indicator e.g. "unique_area_types" to "E1_area_types" --- app.R | 2 +- data_preparation.R | 4 ++-- modules/indicators/E1_server.R | 8 ++++---- modules/indicators/E1_ui.R | 1 - 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app.R b/app.R index 0208dc7..d459b9e 100644 --- a/app.R +++ b/app.R @@ -9,7 +9,7 @@ library(shiny) library(shinydashboard) library(fresh) # for customising shinydashboard look library(shinyWidgets) -library(tidyverse) # added by mahri for fct_reorder() in graph +library(forcats) # added by mahri for fct_reorder() in graph # Data import section ---------------------------------------------------- diff --git a/data_preparation.R b/data_preparation.R index 1d238ba..77bfde9 100644 --- a/data_preparation.R +++ b/data_preparation.R @@ -7,11 +7,11 @@ E1_data <- read.csv("data/E1.csv") %>% rename(dd_bed_days = delayed_discharge_bed_days, fyear = financial_year) -unique_area_types <- E1_data %>% +E1_area_types <- E1_data %>% distinct(area_type) %>% pull(area_type) # For E1 plot 2: -unique_fyear <- E1_data %>% +E1_fyear <- E1_data %>% distinct(fyear) %>% pull(fyear) diff --git a/modules/indicators/E1_server.R b/modules/indicators/E1_server.R index 76a114d..8aa8dea 100644 --- a/modules/indicators/E1_server.R +++ b/modules/indicators/E1_server.R @@ -1,10 +1,10 @@ -# PLOT 1 (MS added title) ---- +# PLOT 1 ---- output$E1_plot1_areaType_output <- renderUI({ shinyWidgets::pickerInput( "E1_plot1_areaType", label = "Select type of geography:", - choices = unique_area_types, + choices = E1_area_types, selected = "Health board") }) @@ -154,7 +154,7 @@ output$E1_plot1 <- renderPlotly({ -# PLOT 2 (MS added all) ---- +# PLOT 2 ---- ## Picker for user selecting Financial Year ---- @@ -162,7 +162,7 @@ output$E1_plot2_year_output <- renderUI({ shinyWidgets::pickerInput( "E1_plot2_year", label = "Select financial year:", - choices = unique_fyear, + choices = E1_fyear, selected = "2022/23") }) diff --git a/modules/indicators/E1_ui.R b/modules/indicators/E1_ui.R index 9fc6fb8..d6572c6 100644 --- a/modules/indicators/E1_ui.R +++ b/modules/indicators/E1_ui.R @@ -26,7 +26,6 @@ tabItem(tabName = "E1_tab", tags$p("Below is a graph showing a comparison between health boards and NHS Scotland for your selected financial year."), # br(), - # tags$p(paste0("Below is a graph showing a comparison between health boards for year "), E1_plot2_year_output), # MS: this is wrong fluidRow( column(6,uiOutput("E1_plot2_year_output")) From e3eea1ad26e88e056e9af0ad1e4b48969bc6a147 Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Wed, 7 Aug 2024 13:39:04 +0100 Subject: [PATCH 31/75] EF4 Server --- modules/indicators/EF4_server.R | 139 ++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 modules/indicators/EF4_server.R diff --git a/modules/indicators/EF4_server.R b/modules/indicators/EF4_server.R new file mode 100644 index 0000000..b39fac8 --- /dev/null +++ b/modules/indicators/EF4_server.R @@ -0,0 +1,139 @@ +### Trends Plot ---- +## Health Board selector +output$EF4_plot1_areaName_output <- renderUI({ + shinyWidgets::pickerInput( + "EF4_plot1_areaName", + label = "Select NHS Health Board:", + choices = EF4_unique_hbnames, + selected = "Health board") +}) + + +## Reactive to create graph data based on HB selection +EF4_plot1_Data <- reactive({ + EF4_data %>% + select(financial_year, hb_name, mh_percent, camhs_percent) %>% + filter(hb_name %in% inputEF4_plot1_areaName) +}) + +## Create plotly bar chart +output$EF4_plot1 <- renderPlotly({ + # + # # # No data plot + # # if(sum(EF4_plot1_Data()$dd_bed_days) == 0 & + # # !is.na(sum(EF4_plot1_Data()$dd_bed_days))) + # # + # # { + # # noDataPlot(phs_colours("phs-purple")) + # # } + # # + # # else { + # + ### Tooltip creation ---- + tooltip_EF4 <- paste0("Financial year: ", + EF4_plot1_Data()$financial_year, + "
", + "Health Board: ", + EF4_plot1_Data()$hb_name, + "
", + "Number of Bed Days: ", + EF4_plot1_Data()$dd_bed_days) + + ### 4 - Create the main body of the chart ---- + + plot_ly(data = EF4_plot1_Data(), + # Select your variables. + x = ~fyear, y = ~dd_bed_days, color = ~area_name, + colors = c("#0080FF"), # line colour - Dark blue for all lines + text = tooltip_EF4, hoverinfo = "text", + type = 'scatter', mode = 'lines+markers', + # width = 600, height = 300, + line = list(width = 3), + marker = list(size = 12), + name = ~str_wrap(area_name, 19)) %>% # legend labels + + ### 7 - Graph title ---- + + # Make the graph title reactive. + + layout(title = + paste0( + "", + "Number of Delayed Discharge Bed Days", " by ", + input$EF4_plot1_areaType, ",", + "
", + first(as.vector(EF4_plot1_Data()$fyear)), + " to ", + last(as.vector(EF4_plot1_Data()$fyear)), + "
", + "
" + ), + + separators = ".", + + yaxis = list( + exponentformat = "none", + separatethousands = TRUE, + range = c(0, max(EF4_plot1_Data()$dd_bed_days, na.rm = TRUE) + + (max(EF4_plot1_Data()$dd_bed_days, na.rm = TRUE)*0.1) + ), + title = paste0(c(rep(" ", 20), + input$EF4_1_input_1, + rep(" ", 20), + rep("\n ", 3))), + showline = TRUE, + ticks = "outside" + ), + + xaxis = list( + title = paste0(c("
", + "Financial year", + collapse = "")), # Don't think it's needed + showline = TRUE, + ticks = "outside" + ), + + margin = list(l = 90, r = 60, b = 180, t = 120), + title = list(size = 15), + font = list(size = 13), + # Legend + showlegend = TRUE, + legend = list(x = 1, + y = 1, + bgcolor = 'rgba(255, 255, 255, 0)', + bordercolor = 'rgba(255, 255, 255, 0)') + # legend = list(orientation = "h", # show entries horizontally + # xanchor = "center", # use center of legend as anchor + # x = 0.5, y = -0.9) # put legend in center of x-axis + ) %>% + + ### 13 - Remove unnecessary buttons from the modebar ---- + + config(displayModeBar = TRUE, + modeBarButtonsToRemove = bttn_remove, + displaylogo = F, editable = F) + + # } + +}) + + +### 15 - Table below graph creation ---- + +# output$EF4_1_trend_table <- renderDataTable({ +# datatable(EF4_plot1_Data(), +# style = 'bootstrap', +# class = 'table-bordered table-condensed', +# rownames = FALSE, +# options = list(pageLength = 16, autoWidth = TRUE, dom = 'tip'), +# colnames = c("Financial year", +# "Area of Residence", +# "Number of Bed Days")) +# }) + + + + + + + From 2167d99733fd92cb7ce97a9be84d0d14154cd75f Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Thu, 8 Aug 2024 18:47:33 +0100 Subject: [PATCH 32/75] EF4 progress --- app.R | 1 + data_preparation.R | 31 +++++++++++++++++++++++++++---- modules/indicators/EF4_server.R | 20 ++++++++++++-------- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/app.R b/app.R index d459b9e..41a2d78 100644 --- a/app.R +++ b/app.R @@ -10,6 +10,7 @@ library(shinydashboard) library(fresh) # for customising shinydashboard look library(shinyWidgets) library(forcats) # added by mahri for fct_reorder() in graph +library(gototop) # Data import section ---------------------------------------------------- diff --git a/data_preparation.R b/data_preparation.R index 77bfde9..f3bbae1 100644 --- a/data_preparation.R +++ b/data_preparation.R @@ -1,8 +1,8 @@ -## Data preparation script +### Data preparation script # N.B. do not use any direct filepaths, ony relational ones -## [Indicators] ---- -# E1 ---- +### [Indicators] ---- +## E1 ---- E1_data <- read.csv("data/E1.csv") %>% rename(dd_bed_days = delayed_discharge_bed_days, fyear = financial_year) @@ -15,9 +15,32 @@ E1_fyear <- E1_data %>% distinct(fyear) %>% pull(fyear) -# EQ1 ---- +## EQ1 ---- EQ1_data <- read.csv("data/EQ1.csv") unique_area_types <- EQ1_data %>% distinct(area_type) %>% pull(area_type) +## EF4 ---- +# Import data and rename variables +EF4_data <- read.csv("data/EF4_Relevant variables.csv") %>% + rename(fyear = financial_year, + "Total Net NHS Expenditure (£ millions)" = total_net_nhs_expenditure, + "Total Mental Health Expenditure (£ millions)" = total_mental_health_expenditure, + "Mental Health Expenditure (%)" = mental_health_expenditure_as_a_percent_of_total_nhs_expenditure, + "CAMHS Expenditure (%)" = camhs_as_percent_of_total_nhs_expenditure) %>% + tidyr::pivot_longer(cols = -(fyear:hb), + names_to = 'measure', + values_to = 'value') + +EF4_fyear <- EF4_data %>% + distinct(fyear) %>% pull(fyear) + +EF4_hb_names <- EF4_data %>% + distinct(hb_name) %>% pull(hb_name) + +EF4_trend_measures <- c('percent_mh', 'percent_camhs') + +# EF4_trend_measures <- EF4_data %>% +# distinct(measure) %>% pull(measure) %>% +# filter(measure = ) diff --git a/modules/indicators/EF4_server.R b/modules/indicators/EF4_server.R index b39fac8..be6cad2 100644 --- a/modules/indicators/EF4_server.R +++ b/modules/indicators/EF4_server.R @@ -1,13 +1,20 @@ ### Trends Plot ---- ## Health Board selector -output$EF4_plot1_areaName_output <- renderUI({ +output$EF4_trendPlot_hbName_output <- renderUI({ shinyWidgets::pickerInput( - "EF4_plot1_areaName", + "EF4_trendPlot_hbName", label = "Select NHS Health Board:", - choices = EF4_unique_hbnames, - selected = "Health board") + choices = EF4_hbnames, + selected = "NHS Ayrshire & Arran") }) +output$EF4_trendPlot_measure_output <- renderUI({ + shinyWidgets::pickerInput( + "EF4_trendPlot_measure", + label = "Select measure:", + choices = EF4_trend_measures, + selected = "Mental Health Expenditure (%)") +}) ## Reactive to create graph data based on HB selection EF4_plot1_Data <- reactive({ @@ -52,10 +59,7 @@ output$EF4_plot1 <- renderPlotly({ marker = list(size = 12), name = ~str_wrap(area_name, 19)) %>% # legend labels - ### 7 - Graph title ---- - - # Make the graph title reactive. - + ### 7 - Graph title ---- layout(title = paste0( "", From 7e3cd5b192d9803b7a777f99eb9d10c9cb7dba62 Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Tue, 13 Aug 2024 16:27:17 +0100 Subject: [PATCH 33/75] EF4 graph v0.1 --- app.R | 7 +- data_preparation.R | 24 ++++--- modules/indicators/EF4_server.R | 111 +++++++++++++++++--------------- modules/indicators/EF4_ui.R | 23 +++++-- 4 files changed, 93 insertions(+), 72 deletions(-) diff --git a/app.R b/app.R index 41a2d78..65cfe34 100644 --- a/app.R +++ b/app.R @@ -1,5 +1,6 @@ -# Loading packages +### Mental Health Quality Indicators Dashboard +# Loading packages library(phsstyles) library(plotly) library(dplyr) @@ -10,7 +11,7 @@ library(shinydashboard) library(fresh) # for customising shinydashboard look library(shinyWidgets) library(forcats) # added by mahri for fct_reorder() in graph -library(gototop) +library(gotop) # Data import section ---------------------------------------------------- @@ -99,6 +100,8 @@ server <- function(input, output, session) { # 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) diff --git a/data_preparation.R b/data_preparation.R index f3bbae1..0aae398 100644 --- a/data_preparation.R +++ b/data_preparation.R @@ -23,15 +23,19 @@ unique_area_types <- EQ1_data %>% ## EF4 ---- # Import data and rename variables -EF4_data <- read.csv("data/EF4_Relevant variables.csv") %>% - rename(fyear = financial_year, - "Total Net NHS Expenditure (£ millions)" = total_net_nhs_expenditure, - "Total Mental Health Expenditure (£ millions)" = total_mental_health_expenditure, - "Mental Health Expenditure (%)" = mental_health_expenditure_as_a_percent_of_total_nhs_expenditure, - "CAMHS Expenditure (%)" = camhs_as_percent_of_total_nhs_expenditure) %>% - tidyr::pivot_longer(cols = -(fyear:hb), - names_to = 'measure', - values_to = 'value') + +# EF4_data <- read.csv("data/EF4_Relevant variables.csv") %>% +# rename(fyear = financial_year, +# "Total Net NHS Expenditure (£ millions)" = total_net_nhs_expenditure, +# "Total Mental Health Expenditure (£ millions)" = total_mental_health_expenditure, +# "Mental Health Expenditure (%)" = mental_health_expenditure_as_a_percent_of_total_nhs_expenditure, +# "CAMHS Expenditure (%)" = camhs_as_percent_of_total_nhs_expenditure) %>% +# tidyr::pivot_longer(cols = -(fyear:hb), +# names_to = 'measure', +# values_to = 'value') + +EF4_data <- read.csv("data/EF4.csv") %>% + select(fyear, hb_name, measure, value) EF4_fyear <- EF4_data %>% distinct(fyear) %>% pull(fyear) @@ -39,7 +43,7 @@ EF4_fyear <- EF4_data %>% EF4_hb_names <- EF4_data %>% distinct(hb_name) %>% pull(hb_name) -EF4_trend_measures <- c('percent_mh', 'percent_camhs') +EF4_trend_measures <- c('Mental Health Expenditure (%)', 'CAMHS Expenditure (%)') # EF4_trend_measures <- EF4_data %>% # distinct(measure) %>% pull(measure) %>% diff --git a/modules/indicators/EF4_server.R b/modules/indicators/EF4_server.R index be6cad2..4565e51 100644 --- a/modules/indicators/EF4_server.R +++ b/modules/indicators/EF4_server.R @@ -1,102 +1,107 @@ -### Trends Plot ---- -## Health Board selector +### EF4 Trends Plot ---- + +## Health Board selector ---- output$EF4_trendPlot_hbName_output <- renderUI({ shinyWidgets::pickerInput( "EF4_trendPlot_hbName", label = "Select NHS Health Board:", - choices = EF4_hbnames, - selected = "NHS Ayrshire & Arran") + choices = EF4_hb_names, + selected = "NHS Scotland") }) +## Measure selector ---- output$EF4_trendPlot_measure_output <- renderUI({ shinyWidgets::pickerInput( "EF4_trendPlot_measure", - label = "Select measure:", + label = "Select measure(s):", choices = EF4_trend_measures, - selected = "Mental Health Expenditure (%)") + selected = "Mental Health Expenditure (%)", + multiple = TRUE) }) -## Reactive to create graph data based on HB selection -EF4_plot1_Data <- reactive({ +## Graph Data Reactive ---- +# to create graph data based on HB and Measure selection +EF4_trendPlot_data <- reactive({ EF4_data %>% - select(financial_year, hb_name, mh_percent, camhs_percent) %>% - filter(hb_name %in% inputEF4_plot1_areaName) + filter(hb_name %in% input$EF4_trendPlot_hbName & + measure %in% input$EF4_trendPlot_measure) }) -## Create plotly bar chart -output$EF4_plot1 <- renderPlotly({ - # +## plotly bar chart ---- +output$EF4_trendPlot <- renderPlotly({ + # # # # No data plot - # # if(sum(EF4_plot1_Data()$dd_bed_days) == 0 & - # # !is.na(sum(EF4_plot1_Data()$dd_bed_days))) - # # + # # if(sum(EF4_trendPlot_data()$value) == 0 & + # # !is.na(sum(EF4_trendPlot_data()$value))) + # # # # { # # noDataPlot(phs_colours("phs-purple")) # # } - # # + # # # # else { - # + # ### Tooltip creation ---- tooltip_EF4 <- paste0("Financial year: ", - EF4_plot1_Data()$financial_year, + EF4_trendPlot_data()$fyear, "
", "Health Board: ", - EF4_plot1_Data()$hb_name, + EF4_trendPlot_data()$hb_name, "
", - "Number of Bed Days: ", - EF4_plot1_Data()$dd_bed_days) - - ### 4 - Create the main body of the chart ---- - - plot_ly(data = EF4_plot1_Data(), + EF4_trendPlot_data()$measure,": ", + EF4_trendPlot_data()$value) + + ## Create the main body of the chart ---- + + plot_ly(data = EF4_trendPlot_data(), # Select your variables. - x = ~fyear, y = ~dd_bed_days, color = ~area_name, - colors = c("#0080FF"), # line colour - Dark blue for all lines + x = ~fyear, y = ~value, color = ~measure, + colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), # line colours text = tooltip_EF4, hoverinfo = "text", type = 'scatter', mode = 'lines+markers', # width = 600, height = 300, - line = list(width = 3), - marker = list(size = 12), - name = ~str_wrap(area_name, 19)) %>% # legend labels - + line = list(width = 2), + linetype = ~measure, + linetypes = c("solid", "dash"), + marker = list(size = 8), + name = ~str_wrap(measure, 19)) %>% # legend labels + ### 7 - Graph title ---- layout(title = paste0( "", - "Number of Delayed Discharge Bed Days", " by ", - input$EF4_plot1_areaType, ",", + "Percent (%) of total NHS spend in ", + input$EF4_trendPlot_hbName_output, ",", "
", - first(as.vector(EF4_plot1_Data()$fyear)), + first(as.vector(EF4_trendPlot_data()$fyear)), " to ", - last(as.vector(EF4_plot1_Data()$fyear)), + last(as.vector(EF4_trendPlot_data()$fyear)), "
", "
" ), - + separators = ".", - + yaxis = list( exponentformat = "none", separatethousands = TRUE, - range = c(0, max(EF4_plot1_Data()$dd_bed_days, na.rm = TRUE) - + (max(EF4_plot1_Data()$dd_bed_days, na.rm = TRUE)*0.1) + range = c(0, max(EF4_trendPlot_data()$value, na.rm = TRUE) + + (max(EF4_trendPlot_data()$value, na.rm = TRUE)*0.1) ), + # Define Y axis title title = paste0(c(rep(" ", 20), - input$EF4_1_input_1, + "Percent", rep(" ", 20), rep("\n ", 3))), showline = TRUE, ticks = "outside" ), - + xaxis = list( - title = paste0(c("
", - "Financial year", - collapse = "")), # Don't think it's needed + title = paste0(c("
", "Financial year")), showline = TRUE, ticks = "outside" ), - + margin = list(l = 90, r = 60, b = 180, t = 120), title = list(size = 15), font = list(size = 13), @@ -110,22 +115,22 @@ output$EF4_plot1 <- renderPlotly({ # xanchor = "center", # use center of legend as anchor # x = 0.5, y = -0.9) # put legend in center of x-axis ) %>% - - ### 13 - Remove unnecessary buttons from the modebar ---- - + + ### Remove unnecessary buttons from the modebar ---- + config(displayModeBar = TRUE, modeBarButtonsToRemove = bttn_remove, displaylogo = F, editable = F) - + # } - + }) -### 15 - Table below graph creation ---- +### Table below graph ---- # output$EF4_1_trend_table <- renderDataTable({ -# datatable(EF4_plot1_Data(), +# datatable(EF4_trendPlot_data(), # style = 'bootstrap', # class = 'table-bordered table-condensed', # rownames = FALSE, diff --git a/modules/indicators/EF4_ui.R b/modules/indicators/EF4_ui.R index dfd6f6a..6c3d5e9 100644 --- a/modules/indicators/EF4_ui.R +++ b/modules/indicators/EF4_ui.R @@ -2,13 +2,22 @@ tabItem(tabName = "EF4_tab", fluidPage( titlePanel("EF4 - Total mental health spend as a % of total spend"), mainPanel( - img(src='infographics/EF4.png', - class = "infographic", - alt = paste0( - "The total (net) mental health expenditure for 2021/22 was ", - "nearly £1,300 million for NHS Scotland, 8.8% of total NHS ", - "expenditure This is an increase from nearly £1,250 million ", - "in 2020/21, 8.8% of total NHS expenditure.")), + tags$p("Below is a graph showing the changes over time."), + + # Graph Selectors + fluidRow( + column(6,uiOutput("EF4_trendPlot_hbName_output")), + column(6,uiOutput("EF4_trendPlot_measure_output")) + ), + # Trend Graph + fluidRow( + plotlyOutput("EF4_trendPlot" + # , + # width = "100%", + # height = "50%" + ) + ), + br(), p("These data are sourced from data collected annually by Public Health Scotland (PHS) on expenditure within NHS Scotland, released in an ", a(href="https://publichealthscotland.scot/media/17844/nhsscotland-mental-health-expenditure.xlsx", From b7f8fb7f3d1a597b04d623e5e4fabeb05bdf7044 Mon Sep 17 00:00:00 2001 From: MahriScot Date: Thu, 15 Aug 2024 15:48:20 +0100 Subject: [PATCH 34/75] 2x E1 warning errors fixed: 1. Plot 1 - Pulling out max. bed day value with a function for adding to y-axis range. 2. Plot 2 - chosing correct filter option after user input. --- modules/indicators/E1_server.R | 42 ++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/modules/indicators/E1_server.R b/modules/indicators/E1_server.R index 8aa8dea..ac7ad02 100644 --- a/modules/indicators/E1_server.R +++ b/modules/indicators/E1_server.R @@ -30,6 +30,19 @@ E1_plot1_Data <- reactive({ & area_name %in% input$E1_plot1_areaName) }) +# Pull out max bed days value for selected georgraph for using in y-axis range later +# (Warning error received without this) +E1_max_bed_days <- reactive({ + E1_data %>% + select(fyear, area_type, area_name, dd_bed_days) %>% + group_by(area_type, area_name) %>% + filter(area_type %in% input$E1_plot1_areaType + & area_name %in% input$E1_plot1_areaName) %>% + slice_max(dd_bed_days) %>% + ungroup() %>% + pull(dd_bed_days) +}) + # Create the discharges line chart. output$E1_plot1 <- renderPlotly({ @@ -87,20 +100,21 @@ output$E1_plot1 <- renderPlotly({ separators = ".", + yaxis = list( - exponentformat = "none", - separatethousands = TRUE, - range = c(0, max(E1_plot1_Data()$dd_bed_days, na.rm = TRUE) - + (max(E1_plot1_Data()$dd_bed_days, na.rm = TRUE)*0.1) - ), - title = paste0(c(rep(" ", 20), - input$E1_1_input_1, - rep(" ", 20), - rep("\n ", 3))), - showline = TRUE, - ticks = "outside" + exponentformat = "none", + separatethousands = TRUE, + range = c(0, E1_max_bed_days() + + (E1_max_bed_days() * 0.1)), + title = paste0(c(rep(" ", 20), + input$E1_1_input_1, + rep(" ", 20), + rep("\n ", 3))), + showline = TRUE, + ticks = "outside" ), - + + xaxis = list( title = paste0(c("
", "Financial year", @@ -163,7 +177,7 @@ output$E1_plot2_year_output <- renderUI({ "E1_plot2_year", label = "Select financial year:", choices = E1_fyear, - selected = "2022/23") + selected = "2023/24") }) ## Selecting appropriate data for graph ---- @@ -172,7 +186,7 @@ E1_plot2_Data <- reactive({ E1_data %>% select(fyear, area_type, area_name, dd_bed_days, rate_per_1000_population) %>% filter(area_type == "Health board") %>% - filter(fyear == input$E1_plot2_year) %>% + filter(fyear %in% input$E1_plot2_year) %>% mutate(area_name = fct_reorder(area_name, rate_per_1000_population)) %>% # for ordering by most to least bed days mutate(to_highlight = if_else(area_name == "NHS Scotland", # for highlighting NHS Scotland "seagreen", "#0080FF")) # changed from "yes" and "no" so that these colours appear on the graph and don't have a legend using "marker = list(color... )" From ae425052f19bdd8bd5967f6afcdaab61201c5143 Mon Sep 17 00:00:00 2001 From: Cormac-Murray Date: Mon, 19 Aug 2024 13:16:04 +0100 Subject: [PATCH 35/75] Creation of second EQ1 chart, with accompanying data. --- data_preparation.R | 8 + modules/indicators/EQ1_server.R | 485 +++++++++++++++++--------------- modules/indicators/EQ1_ui.R | 36 +-- 3 files changed, 288 insertions(+), 241 deletions(-) diff --git a/data_preparation.R b/data_preparation.R index 0aae398..0e8321b 100644 --- a/data_preparation.R +++ b/data_preparation.R @@ -21,6 +21,13 @@ 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") + +unique_area_types_reformatted <- EQ1_reformatted_data %>% + distinct(area_type) %>% pull(area_type) + + ## EF4 ---- # Import data and rename variables @@ -48,3 +55,4 @@ EF4_trend_measures <- c('Mental Health Expenditure (%)', 'CAMHS Expenditure (%)' # EF4_trend_measures <- EF4_data %>% # distinct(measure) %>% pull(measure) %>% # filter(measure = ) + diff --git a/modules/indicators/EQ1_server.R b/modules/indicators/EQ1_server.R index bfe4fd1..03f4fb9 100644 --- a/modules/indicators/EQ1_server.R +++ b/modules/indicators/EQ1_server.R @@ -25,11 +25,13 @@ output$EQ1_plot1_areaName_output <- renderUI({ EQ1_plot1_Data <- reactive({ EQ1_data %>% - select(Year, area_type, area_name, RiskRatio, SMR04_Pop_Rate, General_Pop_Rate) %>% + select(Year, area_type, area_name, risk_ratio, SMR04_Pop_Rate, General_Pop_Rate) %>% filter(area_type %in% input$EQ1_plot1_areaType & area_name %in% input$EQ1_plot1_areaName) }) + + # Create the risk ratios line chart. output$EQ1_plot1 <- renderPlotly({ @@ -53,13 +55,13 @@ output$EQ1_plot1 <- renderPlotly({ EQ1_plot1_Data()$area_name, "
", "Mortality rate: ", - EQ1_plot1_Data()$RiskRatio) + EQ1_plot1_Data()$risk_ratio) ### 4 - Create the main body of the chart ---- plot_ly(data = EQ1_plot1_Data(), # Select your variables. - x = ~Year, y = ~RiskRatio, color = ~area_name, + x = ~Year, y = ~risk_ratio, color = ~area_name, colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), text = tooltip_EQ1, hoverinfo = "text", type = 'scatter', mode = 'lines+markers', @@ -94,8 +96,8 @@ output$EQ1_plot1 <- renderPlotly({ yaxis = list( exponentformat = "none", separatethousands = TRUE, - range = c(0, max(EQ1_plot1_Data()$RiskRatio, na.rm = TRUE) - + (max(EQ1_plot1_Data()$RiskRatio, na.rm = TRUE)*0.1) + range = c(0, max(EQ1_plot1_Data()$risk_ratio, na.rm = TRUE) + + (max(EQ1_plot1_Data()$risk_ratio, na.rm = TRUE)*0.1) ), title = paste0(c(rep(" ", 20), input$EQ1_1_input_1, @@ -138,218 +140,114 @@ output$EQ1_plot1 <- renderPlotly({ }) - - -####### Create the SMR04 rates bar chart. - -output$EQ1_plot2 <- renderPlotly({ - # - # # # No data plot - # # if(sum(E1_plot1_Data()$dd_bed_days) == 0 & - # # !is.na(sum(E1_plot1_Data()$dd_bed_days))) - # # - # # { - # # noDataPlot(phs_colours("phs-purple")) - # # } - # # - # # else { - # - ### 3 - Tooltip creation ---- - - tooltip_EQ1_2 <- paste0("Financial year: ", - EQ1_plot1_Data()$Year, - "
", - "Area of residence: ", - EQ1_plot1_Data()$area_name, - "
", - "Mortality rate: ", - EQ1_plot1_Data()$SMR04_Pop_Rate) - - ### 4 - Create the main body of the chart ---- - - plot_ly(data = EQ1_plot1_Data(), - # Select your variables. - x = ~Year, y = ~SMR04_Pop_Rate, type = 'bar', color = ~area_name, - #add_trace(p = data, y = ~General_Pop_Rate), - colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), - text = tooltip_EQ1_2, hoverinfo = "text", - marker = list(size = 12), - name = ~str_wrap(area_name, 19)) %>% # legend labels - - ### 7 - Graph title ---- - - # Make the graph title reactive. - - layout(title = - paste0( - "", - "Mortality rate for persons in contact with MH services", - "
", - " by ", input$EQ1_plot1_areaType, ", ", first(as.vector(EQ1_plot1_Data()$Year)), - " to ", - last(as.vector(EQ1_plot1_Data()$Year)), - "
", - "
" - ), - - separators = ".", - - yaxis = list( - exponentformat = "none", - separatethousands = TRUE, - range = c(0, max(EQ1_plot1_Data()$SMR04_Pop_Rate, na.rm = TRUE) - + (max(EQ1_plot1_Data()$SMR04_Pop_Rate, na.rm = TRUE)*0.1) - ), - title = paste0(c(rep(" ", 20), - input$EQ1_1_input_1, - rep(" ", 20), - rep("\n ", 3))), - showline = TRUE, - ticks = "outside" - ), - - xaxis = list( - title = paste0(c("
", - "Area name", - collapse = "")), # Don't think it's needed - showline = TRUE, - ticks = "outside" - ), - - margin = list(l = 90, r = 60, b = 180, t = 120), - title = list(size = 15), - font = list(size = 13), - # Legend - showlegend = TRUE, - legend = list(x = 1, - y = 1, - bgcolor = 'rgba(255, 255, 255, 0)', - bordercolor = 'rgba(255, 255, 255, 0)') - # legend = list(orientation = "h", # show entries horizontally - # xanchor = "center", # use center of legend as anchor - # x = 0.5, y = -0.9) # put legend in center of x-axis - ) %>% - - ### 13 - Remove unnecessary buttons from the modebar ---- - - config(displayModeBar = TRUE, - modeBarButtonsToRemove = bttn_remove, - displaylogo = F, editable = F) - - # } - -}) - - - - -####### Create the general population rates bar chart. - -output$EQ1_plot3 <- renderPlotly({ - # - # # # No data plot - # # if(sum(E1_plot1_Data()$dd_bed_days) == 0 & - # # !is.na(sum(E1_plot1_Data()$dd_bed_days))) - # # - # # { - # # noDataPlot(phs_colours("phs-purple")) - # # } - # # - # # else { - # - ### 3 - Tooltip creation ---- - - tooltip_EQ1_3 <- paste0("Financial year: ", - EQ1_plot1_Data()$Year, - "
", - "Area of residence: ", - EQ1_plot1_Data()$area_name, - "
", - "Mortality rate: ", - EQ1_plot1_Data()$General_Pop_Rate) - - ### 4 - Create the main body of the chart ---- - - plot_ly(data = EQ1_plot1_Data(), - # Select your variables. - x = ~Year, y = ~General_Pop_Rate, type = 'bar', color = ~area_name, - #add_trace(p = data, y = ~General_Pop_Rate), - colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), - text = tooltip_EQ1_3, hoverinfo = "text", - marker = list(size = 12), - name = ~str_wrap(area_name, 19)) %>% # legend labels - - ### 7 - Graph title ---- - - # Make the graph title reactive. - - layout(title = - paste0( - "", - "Mortality rate for the general population", - "
", - " by ", input$EQ1_plot1_areaType, ", ", first(as.vector(EQ1_plot1_Data()$Year)), - " to ", - last(as.vector(EQ1_plot1_Data()$Year)), - "
", - "
" - ), - - separators = ".", - - yaxis = list( - exponentformat = "none", - separatethousands = TRUE, - range = c(0, max(EQ1_plot1_Data()$General_Pop_Rate, na.rm = TRUE) - + (max(EQ1_plot1_Data()$General_Pop_Rate, na.rm = TRUE)*0.1) - ), - title = paste0(c(rep(" ", 20), - input$EQ1_1_input_1, - rep(" ", 20), - rep("\n ", 3))), - showline = TRUE, - ticks = "outside" - ), - - xaxis = list( - title = paste0(c("
", - "Area name", - collapse = "")), # Don't think it's needed - showline = TRUE, - ticks = "outside" - ), - - margin = list(l = 90, r = 60, b = 180, t = 120), - title = list(size = 15), - font = list(size = 13), - # Legend - showlegend = TRUE, - legend = list(x = 1, - y = 1, - bgcolor = 'rgba(255, 255, 255, 0)', - bordercolor = 'rgba(255, 255, 255, 0)') - # legend = list(orientation = "h", # show entries horizontally - # xanchor = "center", # use center of legend as anchor - # x = 0.5, y = -0.9) # put legend in center of x-axis - ) %>% - - ### 13 - Remove unnecessary buttons from the modebar ---- - - config(displayModeBar = TRUE, - modeBarButtonsToRemove = bttn_remove, - displaylogo = F, editable = F) - - # } - -}) - - - - - -####### Create the combined general population and MH rates bar chart. # -# output$EQ1_plot4 <- renderPlotly({ +# +# ####### Create the SMR04 rates bar chart. +# +# output$EQ1_plot2 <- renderPlotly({ +# # +# # # # No data plot +# # # if(sum(E1_plot1_Data()$dd_bed_days) == 0 & +# # # !is.na(sum(E1_plot1_Data()$dd_bed_days))) +# # # +# # # { +# # # noDataPlot(phs_colours("phs-purple")) +# # # } +# # # +# # # else { +# # +# ### 3 - Tooltip creation ---- +# +# tooltip_EQ1_2 <- paste0("Financial year: ", +# EQ1_plot1_Data()$Year, +# "
", +# "Area of residence: ", +# EQ1_plot1_Data()$area_name, +# "
", +# "Mortality rate: ", +# EQ1_plot1_Data()$SMR04_Pop_Rate) +# +# ### 4 - Create the main body of the chart ---- +# +# plot_ly(data = EQ1_plot1_Data(), +# # Select your variables. +# x = ~Year, y = ~SMR04_Pop_Rate, type = 'bar', color = ~area_name, +# #add_trace(p = data, y = ~General_Pop_Rate), +# colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), +# text = tooltip_EQ1_2, hoverinfo = "text", +# marker = list(size = 12), +# name = ~str_wrap(area_name, 19)) %>% # legend labels +# +# ### 7 - Graph title ---- +# +# # Make the graph title reactive. +# +# layout(title = +# paste0( +# "", +# "Mortality rate for persons in contact with MH services", +# "
", +# " by ", input$EQ1_plot1_areaType, ", ", first(as.vector(EQ1_plot1_Data()$Year)), +# " to ", +# last(as.vector(EQ1_plot1_Data()$Year)), +# "
", +# "
" +# ), +# +# separators = ".", +# +# yaxis = list( +# exponentformat = "none", +# separatethousands = TRUE, +# range = c(0, max(EQ1_plot1_Data()$SMR04_Pop_Rate, na.rm = TRUE) +# + (max(EQ1_plot1_Data()$SMR04_Pop_Rate, na.rm = TRUE)*0.1) +# ), +# title = paste0(c(rep(" ", 20), +# input$EQ1_1_input_1, +# rep(" ", 20), +# rep("\n ", 3))), +# showline = TRUE, +# ticks = "outside" +# ), +# +# xaxis = list( +# title = paste0(c("
", +# "Area name", +# collapse = "")), # Don't think it's needed +# showline = TRUE, +# ticks = "outside" +# ), +# +# margin = list(l = 90, r = 60, b = 180, t = 120), +# title = list(size = 15), +# font = list(size = 13), +# # Legend +# showlegend = TRUE, +# legend = list(x = 1, +# y = 1, +# bgcolor = 'rgba(255, 255, 255, 0)', +# bordercolor = 'rgba(255, 255, 255, 0)') +# # legend = list(orientation = "h", # show entries horizontally +# # xanchor = "center", # use center of legend as anchor +# # x = 0.5, y = -0.9) # put legend in center of x-axis +# ) %>% +# +# ### 13 - Remove unnecessary buttons from the modebar ---- +# +# config(displayModeBar = TRUE, +# modeBarButtonsToRemove = bttn_remove, +# displaylogo = F, editable = F) +# +# # } +# +# }) +# +# +# +# +# ####### Create the general population rates bar chart. +# +# output$EQ1_plot3 <- renderPlotly({ # # # # # # No data plot # # # if(sum(E1_plot1_Data()$dd_bed_days) == 0 & @@ -363,26 +261,23 @@ output$EQ1_plot3 <- renderPlotly({ # # # ### 3 - Tooltip creation ---- # -# tooltip_EQ1_4 <- paste0("Financial year: ", +# tooltip_EQ1_3 <- paste0("Financial year: ", # EQ1_plot1_Data()$Year, # "
", # "Area of residence: ", # EQ1_plot1_Data()$area_name, # "
", -# "MH population rate: ", -# EQ1_plot1_Data()$SMR04_Pop_Rate, -# "
", -# "General population rate: ", +# "Mortality rate: ", # EQ1_plot1_Data()$General_Pop_Rate) # # ### 4 - Create the main body of the chart ---- # # plot_ly(data = EQ1_plot1_Data(), # # Select your variables. -# x = ~Year, y = ~SMR04_Pop_Rate, type = 'bar', color = ~area_name, -# add_trace(y = ~General_Pop_Rate), +# x = ~Year, y = ~General_Pop_Rate, type = 'bar', color = ~area_name, +# #add_trace(p = data, y = ~General_Pop_Rate), # colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), -# text = tooltip_EQ1_4, hoverinfo = "text", +# text = tooltip_EQ1_3, hoverinfo = "text", # marker = list(size = 12), # name = ~str_wrap(area_name, 19)) %>% # legend labels # @@ -393,7 +288,7 @@ output$EQ1_plot3 <- renderPlotly({ # layout(title = # paste0( # "", -# "Mortality rates for the MH and general population", +# "Mortality rate for the general population", # "
", # " by ", input$EQ1_plot1_areaType, ", ", first(as.vector(EQ1_plot1_Data()$Year)), # " to ", @@ -449,6 +344,146 @@ output$EQ1_plot3 <- renderPlotly({ # # } # # }) +# +# + + + + +output$EQ1_plot4_areaType_output <- renderUI({ + shinyWidgets::pickerInput( + "EQ1_plot4_areaType", + label = "Select type of geography:", + choices = unique_area_types, + selected = "Health board") +}) + +output$EQ1_plot4_areaName_output <- renderUI({ + shinyWidgets::pickerInput( + "EQ1_plot4_areaName", + label = "Select area:", + choices = sort(unique(as.character( + EQ1_reformatted_data$area_name + [EQ1_reformatted_data$area_type %in% input$EQ1_plot4_areaType] + ))) + , + multiple = TRUE, + options = list("max-options" = 1, + `selected-text-format` = "count > 1") + ) +}) + + +EQ1_plot4_Data <- reactive({ + EQ1_reformatted_data %>% + select(Rate_Type, Year, area_type, area_name, Rate) %>% + filter(area_type %in% input$EQ1_plot4_areaType + & area_name %in% input$EQ1_plot4_areaName) +}) + + +####### Create the combined general population and MH rates bar chart. +# + output$EQ1_plot4 <- renderPlotly({ + # + # # # No data plot + # # if(sum(E1_plot1_Data()$dd_bed_days) == 0 & + # # !is.na(sum(E1_plot1_Data()$dd_bed_days))) + # # + # # { + # # noDataPlot(phs_colours("phs-purple")) + # # } + # # + # # else { + # + ### 3 - Tooltip creation ---- + + tooltip_EQ1_4 <- paste0("Financial year: ", + EQ1_plot4_Data()$Year, + "
", + "Area of residence: ", + EQ1_plot4_Data()$area_name, + "
", + "Rate Type: ", + EQ1_plot4_Data()$Rate_Type, + "
", + "Rate: ", + EQ1_plot4_Data()$Rate) + + ### 4 - Create the main body of the chart ---- + + plot_ly(data = EQ1_plot4_Data(), + # Select your variables. + x = ~Year, y = ~Rate, type = 'bar', color = ~Rate_Type, + colors = c("#0078D4", "#B3D7F2"), + textposition = "none", + text = tooltip_EQ1_4, hoverinfo = "text", + marker = list(size = 12), + name = ~str_wrap(Rate_Type, 19)) %>% # legend labels + + ### 7 - Graph title ---- + + # Make the graph title reactive. + + layout(title = + paste0( + "", + "Mortality rates for the MH and general population", + "
", + " for ", input$EQ1_plot4_areaName, ", ", first(as.vector(EQ1_plot4_Data()$Year)), + " to ", + last(as.vector(EQ1_plot4_Data()$Year)), + "
", + "
" + ), + + separators = ".", + + yaxis = list( + exponentformat = "none", + separatethousands = TRUE, + range = c(0, max(EQ1_plot4_Data()$Rate, na.rm = TRUE) + + (max(EQ1_plot4_Data()$Rate, na.rm = TRUE)*0.1) + ), + title = paste0(c(rep(" ", 20), + input$EQ1_1_input_1, + rep(" ", 20), + rep("\n ", 3))), + showline = TRUE, + ticks = "outside" + ), + + xaxis = list( + title = paste0(c("
", + "Area name", + collapse = "")), # Don't think it's needed + showline = TRUE, + ticks = "outside" + ), + + margin = list(l = 90, r = 60, b = 180, t = 120), + title = list(size = 15), + font = list(size = 13), + # Legend + showlegend = TRUE, + legend = list(x = 1, + y = 1, + bgcolor = 'rgba(255, 255, 255, 0)', + bordercolor = 'rgba(255, 255, 255, 0)') + # legend = list(orientation = "h", # show entries horizontally + # xanchor = "center", # use center of legend as anchor + # x = 0.5, y = -0.9) # put legend in center of x-axis + ) %>% + + ### 13 - Remove unnecessary buttons from the modebar ---- + + config(displayModeBar = TRUE, + modeBarButtonsToRemove = bttn_remove, + displaylogo = F, editable = F) + + # } + + }) ### 15 - Table below graph creation ---- diff --git a/modules/indicators/EQ1_ui.R b/modules/indicators/EQ1_ui.R index 00b3a87..4bb769e 100644 --- a/modules/indicators/EQ1_ui.R +++ b/modules/indicators/EQ1_ui.R @@ -19,25 +19,29 @@ tabItem(tabName = "EQ1_tab", ) ), br(), - br(), - fluidRow( - plotlyOutput("EQ1_plot2" - # , - # width = "100%", - # height = "50%" - ) - ), - br(), - br(), + # br(), + # fluidRow( + # plotlyOutput("EQ1_plot2" + # # , + # # width = "100%", + # # height = "50%" + # ) + # ), + # br(), + # br(), + # fluidRow( + # plotlyOutput("EQ1_plot3" + # # , + # # width = "100%", + # # height = "50%" + # ) + # ), + # br(), fluidRow( - plotlyOutput("EQ1_plot3" - # , - # width = "100%", - # height = "50%" - ) + column(6,uiOutput("EQ1_plot4_areaType_output")), + column(6,uiOutput("EQ1_plot4_areaName_output")) ), br(), - br(), fluidRow( plotlyOutput("EQ1_plot4" # , From 2bad464a17976d477c85be19b0b3038b85a1101c Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Mon, 19 Aug 2024 18:13:05 +0100 Subject: [PATCH 36/75] EF4 graph work --- app.R | 4 ++-- functions/plot_functions.R | 27 +++++++++++++++++++++++++++ modules/indicators/EF4_server.R | 29 +++++++++++++++++------------ 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/app.R b/app.R index 65cfe34..3d0441d 100644 --- a/app.R +++ b/app.R @@ -20,11 +20,11 @@ source("scot_hub_data.R") source("setup.R") source("data_preparation.R") -# # 6. sourcing functions created for app (see functions folder) ------------------------------- +# 6. sourcing functions created for app (see functions folder) ------------------------------- list.files("functions") %>% map(~ source(paste0("functions/", .))) -# Source the ui file ---- +# Source the ui files ---- # ui <- source('ui.R', local = TRUE)$value diff --git a/functions/plot_functions.R b/functions/plot_functions.R index ed4cbc4..e9e061e 100755 --- a/functions/plot_functions.R +++ b/functions/plot_functions.R @@ -27,3 +27,30 @@ plot_ly() %>% 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)) + +} diff --git a/modules/indicators/EF4_server.R b/modules/indicators/EF4_server.R index 4565e51..0cd7965 100644 --- a/modules/indicators/EF4_server.R +++ b/modules/indicators/EF4_server.R @@ -52,18 +52,23 @@ output$EF4_trendPlot <- renderPlotly({ ## Create the main body of the chart ---- - plot_ly(data = EF4_trendPlot_data(), - # Select your variables. - x = ~fyear, y = ~value, color = ~measure, - colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), # line colours - text = tooltip_EF4, hoverinfo = "text", - type = 'scatter', mode = 'lines+markers', - # width = 600, height = 300, - line = list(width = 2), - linetype = ~measure, - linetypes = c("solid", "dash"), - marker = list(size = 8), - name = ~str_wrap(measure, 19)) %>% # legend labels + phs_scatterPlot(EF4_trendPlot_data, fyear, value, tooltip_EF4, measure) + + # data = EF4_trendPlot_data(), + # # Select your variables. + # x = ~fyear, y = ~value, + # text = tooltip_EF4, hoverinfo = "text", + # phs_scatterPlot(measure)) + + # color = ~measure, + # colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), # line colours + # type = 'scatter', mode = 'lines+markers', + # # width = 600, height = 300, + # line = list(width = 2), + # linetype = ~measure, + # linetypes = c("solid", "dash"), + # marker = list(size = 8), + # name = ~str_wrap(measure, 19)) %>% # legend labels ### 7 - Graph title ---- layout(title = From 044e753bcd7a6429a7ca3b831e9afcc2fd4f29bc Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Fri, 23 Aug 2024 18:43:50 +0100 Subject: [PATCH 37/75] Changed page layout method EF4, EF2, T1 --- app.R | 1 + modules/indicators/EF2_ui.R | 47 ++++++++++++++------------ modules/indicators/EF4_server.R | 37 +++++++++++++-------- modules/indicators/EF4_ui.R | 59 ++++++++++++++++++--------------- modules/indicators/T1_ui.R | 52 +++++++++++++++-------------- 5 files changed, 110 insertions(+), 86 deletions(-) diff --git a/app.R b/app.R index 3d0441d..7610dbd 100644 --- a/app.R +++ b/app.R @@ -12,6 +12,7 @@ library(fresh) # for customising shinydashboard look library(shinyWidgets) library(forcats) # added by mahri for fct_reorder() in graph library(gotop) +library(bslib) # Data import section ---------------------------------------------------- diff --git a/modules/indicators/EF2_ui.R b/modules/indicators/EF2_ui.R index 64f809e..b02d173 100644 --- a/modules/indicators/EF2_ui.R +++ b/modules/indicators/EF2_ui.R @@ -1,22 +1,29 @@ tabItem(tabName = "EF2_tab", fluidPage( - titlePanel("EF2 - Readmissions to hospital within 28 days of discharge"), - mainPanel( - img(src='infographics/EF2.png', - class = "infographic", - alt = paste0( - "The percentage of emergency readmissions within 28 days in ", - "Scotland was 7.3% for the year-long period ending 31 March ", - "2023. This compares with 7.8% for the year ending 31 March ", - "2022 and 9.3% for the year ending 31 March 2021.")), - br(), - p("The data for EF1 is sourced from ", - a(href="https://www.nssdiscovery.scot.nhs.uk/", - "Discovery"), - " using SMR04 data.", - a(href="https://publichealthscotland.scot/services/data-management/data-management-in-secondary-care-hospital-activity/scottish-morbidity-records-smr/completeness/", - "Data completeness"), - " for SMR04 was around 90% or better when the data was accessed."), + h1("EF2 - Readmissions to hospital within 28 days of discharge"), + fluidRow( + box(width = NULL, + img(src='infographics/EF2.png', + class = c("infographic", "box"), + alt = paste0( + "The percentage of emergency readmissions within 28 days in ", + "Scotland was 7.3% for the year-long period ending 31 March ", + "2023. This compares with 7.8% for the year ending 31 March ", + "2022 and 9.3% for the year ending 31 March 2021.")) + + + ), + + box(width = NULL, + p("The data for EF1 is sourced from ", + a(href="https://www.nssdiscovery.scot.nhs.uk/", + "Discovery"), + " using SMR04 data.", + a(href="https://publichealthscotland.scot/services/data-management/data-management-in-secondary-care-hospital-activity/scottish-morbidity-records-smr/completeness/", + "Data completeness"), + " for SMR04 was around 90% or better when the data was accessed.") + ) + ), fluidRow( column(4, actionButton(inputId = "EF2_scot_hub_button", @@ -28,8 +35,6 @@ tabItem(tabName = "EF2_tab", column(4, actionButton(inputId = "EF3_nextButton", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) - ) - ) # End of mainPanel + ) # End of fluidRow ) # End of fluidPage - -) \ No newline at end of file +) # End of tabItem \ No newline at end of file diff --git a/modules/indicators/EF4_server.R b/modules/indicators/EF4_server.R index 0cd7965..3005a9a 100644 --- a/modules/indicators/EF4_server.R +++ b/modules/indicators/EF4_server.R @@ -52,23 +52,34 @@ output$EF4_trendPlot <- renderPlotly({ ## Create the main body of the chart ---- - phs_scatterPlot(EF4_trendPlot_data, fyear, value, tooltip_EF4, measure) + # phs_scatterPlot(EF4_trendPlot_data, fyear, value, tooltip_EF4, measure) + + plot_ly(data = EF4_trendPlot_data(), + # Select your variables. + x = ~fyear, y = ~value, color = ~measure, + text = tooltip_EF4, hoverinfo = "text", + colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), # line colours + type = 'scatter', mode = 'lines+markers', + # width = 600, height = 300, + line = list(width = 2), + linetype = ~measure, + linetypes = c("solid", "dash"), + marker = list(size = 8), + name = ~str_wrap(measure, 19)) %>% # legend labels # data = EF4_trendPlot_data(), # # Select your variables. - # x = ~fyear, y = ~value, + # x = ~fyear, y = ~value, # text = tooltip_EF4, hoverinfo = "text", - # phs_scatterPlot(measure)) - - # color = ~measure, - # colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), # line colours - # type = 'scatter', mode = 'lines+markers', - # # width = 600, height = 300, - # line = list(width = 2), - # linetype = ~measure, - # linetypes = c("solid", "dash"), - # marker = list(size = 8), - # name = ~str_wrap(measure, 19)) %>% # legend labels + # color = ~measure, + # colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), # line colours + # type = 'scatter', mode = 'lines+markers', + # # width = 600, height = 300, + # line = list(width = 2), + # linetype = ~measure, + # linetypes = c("solid", "dash"), + # marker = list(size = 8), + # name = ~str_wrap(measure, 19)) %>% # legend labels ### 7 - Graph title ---- layout(title = diff --git a/modules/indicators/EF4_ui.R b/modules/indicators/EF4_ui.R index 6c3d5e9..4dc0745 100644 --- a/modules/indicators/EF4_ui.R +++ b/modules/indicators/EF4_ui.R @@ -1,31 +1,37 @@ tabItem(tabName = "EF4_tab", fluidPage( - titlePanel("EF4 - Total mental health spend as a % of total spend"), - mainPanel( - tags$p("Below is a graph showing the changes over time."), - - # Graph Selectors - fluidRow( - column(6,uiOutput("EF4_trendPlot_hbName_output")), - column(6,uiOutput("EF4_trendPlot_measure_output")) - ), - # Trend Graph - fluidRow( - plotlyOutput("EF4_trendPlot" - # , - # width = "100%", - # height = "50%" - ) + # Defining the title + h1("EF4 - Total mental health spend as a % of total spend"), + fluidRow( + column(6, + box(width = NULL, + uiOutput("EF4_trendPlot_hbName_output")) + ), + column(6, + box(width = NULL, + uiOutput("EF4_trendPlot_measure_output")) + ), + ), + # ), + fluidRow( + box(width = 12, + plotlyOutput("EF4_trendPlot", + # height = "50vh", + width = "100%")) ), - - br(), - p("These data are sourced from data collected annually by Public Health Scotland (PHS) on expenditure within NHS Scotland, released in an ", - a(href="https://publichealthscotland.scot/media/17844/nhsscotland-mental-health-expenditure.xlsx", - "excel workbook "), - "which also includes data for organisations providing these services (14 territorial NHS Boards and the State Hospital at Carstairs Lanarkshire), as part of the ", - a(href="https://publichealthscotland.scot/publications/scottish-health-service-costs/scottish-health-service-costs-high-level-costs-summary-2021-to-2022/", - "annual release of National Statistics covering expenditure in the financial year 2021/22.")), + fluidRow( + column(12, + box(width = NULL, + p("These data are sourced from data collected annually by Public Health Scotland (PHS) on expenditure within NHS Scotland, released in an ", + a(href="https://publichealthscotland.scot/media/17844/nhsscotland-mental-health-expenditure.xlsx", + "excel workbook "), + "which also includes data for organisations providing these services (14 territorial NHS Boards and the State Hospital at Carstairs Lanarkshire), as part of the ", + a(href="https://publichealthscotland.scot/publications/scottish-health-service-costs/scottish-health-service-costs-high-level-costs-summary-2021-to-2022/", + "annual release of National Statistics covering expenditure in the financial year 2021/22."))) + ), + ), + fluidRow( column(4, actionButton(inputId = "EF4_scot_hub_button", label = "Scotland Hub", icon = icon("home"), @@ -37,7 +43,6 @@ tabItem(tabName = "EF4_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of mainPanel ) # End of fluidPage - -) \ No newline at end of file +) + \ No newline at end of file diff --git a/modules/indicators/T1_ui.R b/modules/indicators/T1_ui.R index 4b47630..779fd50 100644 --- a/modules/indicators/T1_ui.R +++ b/modules/indicators/T1_ui.R @@ -1,29 +1,31 @@ tabItem(tabName = "T1_tab", fluidPage( - titlePanel(h1("T1 - % of people who commence Psychological therapy - based treatment within 18 weeks of referral"), - h2("Last Updated: Septemberr 2023")), - mainPanel( - img(src='infographics/T1.png', - class = "infographic", - alt = paste0( - "More than four fifths (84.4%) of people started treatment ", - "within 18 weeks of referral in the quarter ending 31 December 2021", - "compared to 87.2% for the previous quarter, and 80% for the ", - "quarter ending 31 December 2020")), - br(), - p("Further information can be found in the ", - a(href="https://publichealthscotland.scot/publications/psychological-therapies-waiting-times/", - "Psychological Therapies Waiting Times publication"), - ".") - ), - fluidRow( - column(4, actionButton(inputId = "T1_scot_hub_button", - label = "Scotland Hub", icon = icon("home"), - class = "navpageButton")), - column(4, actionButton(inputId = "T2_nextButton", - label = "Next Page - T2", icon = icon("arrow-right"), - class = "navpageButton")) - ) + h1("T1 - % of people who commence Psychological therapy based treatment within 18 weeks of referral"), + h2("Last Updated: Septemberr 2023"), + box(width = 12, + img(src='infographics/T1.png', + class = "infographic", + alt = paste0( + "More than four fifths (84.4%) of people started treatment ", + "within 18 weeks of referral in the quarter ending 31 December 2021", + "compared to 87.2% for the previous quarter, and 80% for the ", + "quarter ending 31 December 2020")) + ), + + box(width = 12, + p("Further information can be found in the ", + a(href="https://publichealthscotland.scot/publications/psychological-therapies-waiting-times/", + "Psychological Therapies Waiting Times publication"), + ".") + ), + fluidRow( + column(4, actionButton(inputId = "T1_scot_hub_button", + label = "Scotland Hub", icon = icon("home"), + class = "navpageButton")), + column(4, actionButton(inputId = "T2_nextButton", + label = "Next Page - T2", icon = icon("arrow-right"), + class = "navpageButton")) + ) + ) # End of fluidPage ) # End of tab \ No newline at end of file From c320c1dfa64f6954825375d4b164759be2f66283 Mon Sep 17 00:00:00 2001 From: MahriScot Date: Thu, 29 Aug 2024 09:38:47 +0100 Subject: [PATCH 38/75] Changing E1 graph code from just using plotly to running it through ggplot first. (Old code commented out until we make a decision) --- app.R | 1 + modules/indicators/E1_server.R | 569 +++++++++++++++++++++------------ modules/indicators/E1_ui.R | 8 +- 3 files changed, 362 insertions(+), 216 deletions(-) diff --git a/app.R b/app.R index 7610dbd..feb0508 100644 --- a/app.R +++ b/app.R @@ -3,6 +3,7 @@ # Loading packages library(phsstyles) library(plotly) +library(ggplot2) # adding for testing using this before plotly library(dplyr) library(purrr) library(stringr) diff --git a/modules/indicators/E1_server.R b/modules/indicators/E1_server.R index ac7ad02..bfbbf9e 100644 --- a/modules/indicators/E1_server.R +++ b/modules/indicators/E1_server.R @@ -1,169 +1,265 @@ # PLOT 1 ---- +## Picker for user selecting HB or CA ---- + output$E1_plot1_areaType_output <- renderUI({ - shinyWidgets::pickerInput( - "E1_plot1_areaType", - label = "Select type of geography:", - choices = E1_area_types, - selected = "Health board") + shinyWidgets::pickerInput( + "E1_plot1_areaType", + label = "Select type of geography:", + choices = E1_area_types, + selected = "Health board") }) +## Picker for user selecting specific geographies ---- + output$E1_plot1_areaName_output <- renderUI({ - shinyWidgets::pickerInput( - "E1_plot1_areaName", - label = "Select area(s) (Maximum 5):", - choices = sort(unique(as.character( - E1_data$area_name - [E1_data$area_type %in% input$E1_plot1_areaType] - ))) - # , - # multiple = TRUE, - # options = list("max-options" = 5, - # `selected-text-format` = "count > 1") - ) + shinyWidgets::pickerInput( + "E1_plot1_areaName", + label = "Select area(s) (Maximum 5):", + selected = "NHS Ayrshire & Arran", + choices = sort(unique(as.character( + E1_data$area_name + [E1_data$area_type %in% input$E1_plot1_areaType] + ))) + # , + # multiple = TRUE, + # options = list("max-options" = 5, + # `selected-text-format` = "count > 1") + ) }) +## Selecting appropriate data for graph 1 ---- +### Is this where the error "Argument 1 is not a Vector" is coming from? ---- E1_plot1_Data <- reactive({ - E1_data %>% - select(fyear, area_type, area_name, dd_bed_days) %>% - filter(area_type %in% input$E1_plot1_areaType - & area_name %in% input$E1_plot1_areaName) -}) - -# Pull out max bed days value for selected georgraph for using in y-axis range later -# (Warning error received without this) -E1_max_bed_days <- reactive({ - E1_data %>% + E1_data %>% select(fyear, area_type, area_name, dd_bed_days) %>% - group_by(area_type, area_name) %>% - filter(area_type %in% input$E1_plot1_areaType - & area_name %in% input$E1_plot1_areaName) %>% - slice_max(dd_bed_days) %>% - ungroup() %>% - pull(dd_bed_days) + filter(area_type %in% input$E1_plot1_areaType # don't think we really need this first filter but doesn't harm anything? + & area_name %in% input$E1_plot1_areaName) }) + -# Create the discharges line chart. +# Create the discharges line chart ---- -output$E1_plot1 <- renderPlotly({ -# -# # # No data plot -# # if(sum(E1_plot1_Data()$dd_bed_days) == 0 & -# # !is.na(sum(E1_plot1_Data()$dd_bed_days))) -# # -# # { -# # noDataPlot(phs_colours("phs-purple")) -# # } -# # -# # else { -# - ### 3 - Tooltip creation ---- - - tooltip_E1 <- paste0("Financial year: ", - E1_plot1_Data()$fyear, - "
", - "Area of residence: ", - E1_plot1_Data()$area_name, - "
", - "Number of Bed Days: ", - E1_plot1_Data()$dd_bed_days) - - ### 4 - Create the main body of the chart ---- - - plot_ly(data = E1_plot1_Data(), - # Select your variables. - x = ~fyear, y = ~dd_bed_days, color = ~area_name, - colors = c("#0080FF"), # line colour - Dark blue for all lines - text = tooltip_E1, hoverinfo = "text", - type = 'scatter', mode = 'lines+markers', - # width = 600, height = 300, - line = list(width = 3), - marker = list(size = 12), - name = ~str_wrap(area_name, 19)) %>% # legend labels - - ### 7 - Graph title ---- - - # Make the graph title reactive. - - layout(title = - paste0( - "", - "Number of Delayed Discharge Bed Days", " by ", - input$E1_plot1_areaType, ",", - "
", - first(as.vector(E1_plot1_Data()$fyear)), - " to ", - last(as.vector(E1_plot1_Data()$fyear)), - "
", - "
" - ), - - separators = ".", - - - yaxis = list( - exponentformat = "none", - separatethousands = TRUE, - range = c(0, E1_max_bed_days() - + (E1_max_bed_days() * 0.1)), - title = paste0(c(rep(" ", 20), - input$E1_1_input_1, - rep(" ", 20), - rep("\n ", 3))), - showline = TRUE, - ticks = "outside" - ), - - - xaxis = list( - title = paste0(c("
", - "Financial year", - collapse = "")), # Don't think it's needed - showline = TRUE, - ticks = "outside" - ), - - margin = list(l = 90, r = 60, b = 180, t = 120), - title = list(size = 15), - font = list(size = 13), - # Legend - showlegend = TRUE, - legend = list(x = 1, - y = 1, - bgcolor = 'rgba(255, 255, 255, 0)', - bordercolor = 'rgba(255, 255, 255, 0)') - # legend = list(orientation = "h", # show entries horizontally - # xanchor = "center", # use center of legend as anchor - # x = 0.5, y = -0.9) # put legend in center of x-axis - ) %>% - - ### 13 - Remove unnecessary buttons from the modebar ---- - - config(displayModeBar = TRUE, - modeBarButtonsToRemove = bttn_remove, - displaylogo = F, editable = F) - - # } - -}) +## Testing new code ---- + ### Render plotly ---- -### 15 - Table below graph creation ---- +output$E1_plot1 <- renderPlotly({ + + ### Create reactive ggplot graph ---- + + E1_plot1_graph <- reactive({ + ggplot(data = E1_plot1_Data(), + aes(x = fyear, + y = dd_bed_days, + group = area_name, + color = area_name, + text = paste0("Financial year: ", + E1_plot1_Data()$fyear, + "
", + "Area of residence: ", + E1_plot1_Data()$area_name, + "
", + "Total number of bed days: ", + E1_plot1_Data()$dd_bed_days) # for tooltip in ggplotly - shows values on hover + ) + ) + + geom_line(color = "black") + + geom_point(color = "black", fill = "black") + + theme_classic() + # I normally use bw but will see what this looks like (de-clutters graph background) + theme(panel.grid.major.x = element_line(), # Shows vertical grid lines + panel.grid.major.y = element_line(), # Shows horizontal grid lines + axis.title.x = element_text(size = 12, + color = "black", + face = "bold"), + axis.title.y = element_text(size = 12, + color = "black", + face = "bold"), + legend.position = "none") + # removes legend + labs(x = "Financial Year", y = "Number of Days") + + scale_y_continuous(limits = c(0, (max(E1_data$dd_bed_days))), # Keeps the y-axis the same length for all graphs, ranges from 0 to the max value plus 9 so that the last tick can be seen + breaks = seq(0, (max(E1_data$dd_bed_days)), by = 10)) # y-axis ticks range from 0 to the max value + 9, showing increments of 10 + + }) + + ### Run graph 1 through plotly ---- + + ggplotly(E1_plot1_graph(), + tooltip = "text")#, # uses text set up in ggplot aes above. + # ### Remove unnecessary buttons from the modebar ---- not working just now + # config(displayModeBar = TRUE, # Remove unnecessary buttons from the modebar + # modeBarButtonsToRemove = bttn_remove, + # displaylogo = F, editable = F)) + +}) -# output$E1_1_trend_table <- renderDataTable({ -# datatable(E1_plot1_Data(), -# style = 'bootstrap', -# class = 'table-bordered table-condensed', -# rownames = FALSE, -# options = list(pageLength = 16, autoWidth = TRUE, dom = 'tip'), -# colnames = c("Financial year", -# "Area of Residence", -# "Number of Bed Days")) -# }) +## X ALL OF THE OLD CODE FOR PLOT 1 ---- +# # PLOT 1 ---- +# +# output$E1_plot1_areaType_output <- renderUI({ +# shinyWidgets::pickerInput( +# "E1_plot1_areaType", +# label = "Select type of geography:", +# choices = E1_area_types, +# selected = "Health board") +# }) +# +# output$E1_plot1_areaName_output <- renderUI({ +# shinyWidgets::pickerInput( +# "E1_plot1_areaName", +# label = "Select area(s) (Maximum 5):", +# choices = sort(unique(as.character( +# E1_data$area_name +# [E1_data$area_type %in% input$E1_plot1_areaType] +# ))) +# # , +# # multiple = TRUE, +# # options = list("max-options" = 5, +# # `selected-text-format` = "count > 1") +# ) +# }) +# +# E1_plot1_Data <- reactive({ +# E1_data %>% +# select(fyear, area_type, area_name, dd_bed_days) %>% +# filter(area_type %in% input$E1_plot1_areaType +# & area_name %in% input$E1_plot1_areaName) +# }) +# +# # Pull out max bed days value for selected georgraph for using in y-axis range later +# # (Warning error received without this) +# E1_max_bed_days <- reactive({ +# E1_data %>% +# select(fyear, area_type, area_name, dd_bed_days) %>% +# group_by(area_type, area_name) %>% +# filter(area_type %in% input$E1_plot1_areaType +# & area_name %in% input$E1_plot1_areaName) %>% +# slice_max(dd_bed_days) %>% +# ungroup() %>% +# pull(dd_bed_days) +# }) +# +# # Create the discharges line chart. +# +# output$E1_plot1 <- renderPlotly({ +# # +# # # # No data plot +# # # if(sum(E1_plot1_Data()$dd_bed_days) == 0 & +# # # !is.na(sum(E1_plot1_Data()$dd_bed_days))) +# # # +# # # { +# # # noDataPlot(phs_colours("phs-purple")) +# # # } +# # # +# # # else { +# # +# ### 3 - Tooltip creation ---- +# +# tooltip_E1 <- paste0("Financial year: ", +# E1_plot1_Data()$fyear, +# "
", +# "Area of residence: ", +# E1_plot1_Data()$area_name, +# "
", +# "Number of Bed Days: ", +# E1_plot1_Data()$dd_bed_days) +# +# ### 4 - Create the main body of the chart ---- +# +# plot_ly(data = E1_plot1_Data(), +# # Select your variables. +# x = ~fyear, y = ~dd_bed_days, color = ~area_name, +# colors = c("#0080FF"), # line colour - Dark blue for all lines +# text = tooltip_E1, hoverinfo = "text", +# type = 'scatter', mode = 'lines+markers', +# # width = 600, height = 300, +# line = list(width = 3), +# marker = list(size = 12), +# name = ~str_wrap(area_name, 19)) %>% # legend labels +# +# ### 7 - Graph title ---- +# +# # Make the graph title reactive. +# +# layout(title = +# paste0( +# "", +# "Number of Delayed Discharge Bed Days", " by ", +# input$E1_plot1_areaType, ",", +# "
", +# first(as.vector(E1_plot1_Data()$fyear)), +# " to ", +# last(as.vector(E1_plot1_Data()$fyear)), +# "
", +# "
" +# ), +# +# separators = ".", +# +# +# yaxis = list( +# exponentformat = "none", +# separatethousands = TRUE, +# range = c(0, E1_max_bed_days() +# + (E1_max_bed_days() * 0.1)), +# title = paste0(c(rep(" ", 20), +# input$E1_1_input_1, +# rep(" ", 20), +# rep("\n ", 3))), +# showline = TRUE, +# ticks = "outside" +# ), +# +# +# xaxis = list( +# title = paste0(c("
", +# "Financial year", +# collapse = "")), # Don't think it's needed +# showline = TRUE, +# ticks = "outside" +# ), +# +# margin = list(l = 90, r = 60, b = 180, t = 120), +# title = list(size = 15), +# font = list(size = 13), +# # Legend +# showlegend = TRUE, +# legend = list(x = 1, +# y = 1, +# bgcolor = 'rgba(255, 255, 255, 0)', +# bordercolor = 'rgba(255, 255, 255, 0)') +# # legend = list(orientation = "h", # show entries horizontally +# # xanchor = "center", # use center of legend as anchor +# # x = 0.5, y = -0.9) # put legend in center of x-axis +# ) %>% +# +# ### 13 - Remove unnecessary buttons from the modebar ---- +# +# config(displayModeBar = TRUE, +# modeBarButtonsToRemove = bttn_remove, +# displaylogo = F, editable = F) +# +# # } +# +# }) +# +# +# ### 15 - Table below graph creation ---- +# +# # output$E1_1_trend_table <- renderDataTable({ +# # datatable(E1_plot1_Data(), +# # style = 'bootstrap', +# # class = 'table-bordered table-condensed', +# # rownames = FALSE, +# # options = list(pageLength = 16, autoWidth = TRUE, dom = 'tip'), +# # colnames = c("Financial year", +# # "Area of Residence", +# # "Number of Bed Days")) +# # }) @@ -180,7 +276,7 @@ output$E1_plot2_year_output <- renderUI({ selected = "2023/24") }) -## Selecting appropriate data for graph ---- +## Selecting appropriate data for graph 2 ---- E1_plot2_Data <- reactive({ E1_data %>% @@ -194,73 +290,122 @@ E1_plot2_Data <- reactive({ -## Create the discharges bar chart. ---- +# Create the discharges bar chart ---- -output$E1_plot2 <- renderPlotly({ + ## Testing new code ---- - ### Hover Text - Tooltip creation (doesn't quite work) ---- + ### Render plotly ---- - tooltip_E1_plot2 <- paste0("Area of residence: ", - E1_plot2_Data()$area_name, - "
", - "Number of Bed Days per 1000 population: ", - E1_plot2_Data()$dd_bed_days) - - ### Create the main body of the chart ---- - - plot_ly(data = E1_plot2_Data(), - # Select your variables. - - x = ~rate_per_1000_population, - y = ~area_name, - # fill = ~to_highlight, # highlighting Scotland but this is working with color and colors below - marker = list(color = ~to_highlight), # This stops the colour legend appearing on the hover. Using color= and colors= below adds the legend - # color = ~to_highlight, - # colors = c("#0080FF", "seagreen"), # line colour - Dark blue for all lines. seagreen for test - #text = tooltip_E1_plot2, # This and hoverinfo = "text" were showing the info when hovering AND permanently on the graph - # hoverinfo = "text", - hoverinfo = tooltip_E1_plot2, - type = 'bar', - orientation = 'h') %>% +output$E1_plot2 <- renderPlotly({ - + ### Create reactive ggplot graph ---- + +E1_plot2_graph <- reactive({ + ggplot(E1_plot2_Data(), + aes(x = rate_per_1000_population, + y = area_name, + fill = to_highlight, # colours defined below (highlights NHS Scotland) + text = paste0("Financial year: ", fyear, # for tooltip in ggplotly - shows values on hover + "
", + "Area of residence: ", area_name, + "
", + "Bed days per 1,000 population: ", rate_per_1000_population) + )) + + geom_bar(stat = "identity") + # creates bar graph with bars separated from each other + scale_fill_manual(values = c("#0080FF", "seagreen")) + # highlights NHS Scotland + theme_classic() + # I normally use bw but will see what this looks like (de-clutters graph background) + theme(panel.grid.major.x = element_line(), # Shows vertical grid lines + panel.grid.major.y = element_line(), # Shows horizontal grid lines + axis.title.x = element_text(size = 12, + color = "black", + face = "bold"), + axis.title.y = element_blank(), + legend.position = "none") + # removes legend + labs(x = "Number of Days per 1,000 Population", y = NULL) + + scale_x_continuous(limits = c(0, (max(E1_data$rate_per_1000_population) + 9)), # Keeps the x-axis the same length for all graphs, ranges from 0 to the max value plus 9 so that the last tick can be seen + breaks = seq(0, (max(E1_data$rate_per_1000_population) + 9), by = 10)) # x-axis ticks range from 0 to the max value + 9, showing increments of 10 - ### Graph layout and titles ----- - - layout( - margin = list(l=0, r=20, b=25, t=50, pad=3), # i only see a difference in the top and the padding, but this adds space around title, axis titles, padding is around graph itself (between axis and values) ("left, right, bottom, top, padding") - - title = paste0("", - "Delayed Discharge Bed Days for the Financial Year: ", input$E1_plot2_year, - "
", - "
"), - # title = list(standoff = 1), # tried lots of ways of doing this but nothing working - #title = list(size = 12, y = 5, x = 0, xanchor = 'center', yanchor = 'top'), # none of this does anything to change things (no variation of any of them) - - separators = ".", - - yaxis = list(title =""), - - # Re: xasis, I wanted the axis range to be "0:whatever the highest value is across ALL - # years" for every year's graph. Things I tried, that didn't work, included: - # rangemode = "tozero" - # tick0 = 0 - # range = list(c(0, 300), round(max(E1_data$rate_per_1000_population), 10)), # ensures all graphs have the same range of 0-300 days but the graph wasn't starting at 0 (As bed days are going up each year, "round(...,10)" sets the xaxis as 10 more than whatever the new data shows as the maximum value) - xaxis = list(title = "Number of Days", - dtick = 10, # shows a marker for every 10th number of bed days - # range = c(~min(c(-1, E1_data$rate_per_1000_population)), ~max(c(1, E1_data$rate_per_1000_population))), # I can't work out why this might be better when the below works too - range = c(~min(0), ~max(c(1, E1_data$rate_per_1000_population))), - autorange = FALSE), # if it were TRUE then the range would change for each graph - - - font = list(size = 12), - - showlegend = FALSE) %>% - - ### Remove unnecessary buttons from the modebar ---- - - config(displayModeBar = TRUE, - modeBarButtonsToRemove = bttn_remove, - displaylogo = F, editable = F) - -}) \ No newline at end of file +}) + ### Run graph 2 through plotly ---- + +ggplotly(E1_plot2_graph(), + tooltip = "text")#, # uses text set up in ggplot aes above. + # ### Remove unnecessary buttons from the modebar ---- not working but will make work + # config(displayModeBar = TRUE, + # modeBarButtonsToRemove = bttn_remove, + # displaylogo = F, editable = F)) + +}) + + + + +## x OLD PLOTLY CODE - PLOT 2 ---- +# output$E1_plot2 <- renderPlotly({ +# + #### Hover Text - Tooltip creation (doesn't quite work) ---- +# +# tooltip_E1_plot2 <- paste0("Area of residence: ", +# E1_plot2_Data()$area_name, +# "
", +# "Number of Bed Days per 1000 population: ", +# E1_plot2_Data()$dd_bed_days) +# + #### Create the main body of the chart ---- +# +# plot_ly(data = E1_plot2_Data(), +# # Select your variables. +# +# x = ~rate_per_1000_population, +# y = ~area_name, +# # fill = ~to_highlight, # highlighting Scotland but this is working with color and colors below +# marker = list(color = ~to_highlight), # This stops the colour legend appearing on the hover. Using color= and colors= below adds the legend +# # color = ~to_highlight, +# # colors = c("#0080FF", "seagreen"), # line colour - Dark blue for all lines. seagreen for test +# #text = tooltip_E1_plot2, # This and hoverinfo = "text" were showing the info when hovering AND permanently on the graph +# # hoverinfo = "text", +# hoverinfo = tooltip_E1_plot2, +# type = 'bar', +# orientation = 'h') %>% +# +# +# + #### Graph layout and titles ----- +# +# layout( +# margin = list(l=0, r=20, b=25, t=50, pad=3), # i only see a difference in the top and the padding, but this adds space around title, axis titles, padding is around graph itself (between axis and values) ("left, right, bottom, top, padding") +# +# title = paste0("", +# "Delayed Discharge Bed Days for the Financial Year: ", input$E1_plot2_year, +# "
", +# "
"), +# # title = list(standoff = 1), # tried lots of ways of doing this but nothing working +# #title = list(size = 12, y = 5, x = 0, xanchor = 'center', yanchor = 'top'), # none of this does anything to change things (no variation of any of them) +# +# separators = ".", +# +# yaxis = list(title =""), +# +# # Re: xasis, I wanted the axis range to be "0:whatever the highest value is across ALL +# # years" for every year's graph. Things I tried, that didn't work, included: +# # rangemode = "tozero" +# # tick0 = 0 +# # range = list(c(0, 300), round(max(E1_data$rate_per_1000_population), 10)), # ensures all graphs have the same range of 0-300 days but the graph wasn't starting at 0 (As bed days are going up each year, "round(...,10)" sets the xaxis as 10 more than whatever the new data shows as the maximum value) +# xaxis = list(title = "Number of Days", +# dtick = 10, # shows a marker for every 10th number of bed days +# # range = c(~min(c(-1, E1_data$rate_per_1000_population)), ~max(c(1, E1_data$rate_per_1000_population))), # I can't work out why this might be better when the below works too +# range = c(~min(0), ~max(c(1, E1_data$rate_per_1000_population))), +# autorange = FALSE), # if it were TRUE then the range would change for each graph +# +# +# font = list(size = 12), +# +# showlegend = FALSE) %>% +# + #### Remove unnecessary buttons from the modebar ---- +# +# config(displayModeBar = TRUE, +# modeBarButtonsToRemove = bttn_remove, +# displaylogo = F, editable = F) +# +# }) \ No newline at end of file diff --git a/modules/indicators/E1_ui.R b/modules/indicators/E1_ui.R index d6572c6..1dd25fc 100644 --- a/modules/indicators/E1_ui.R +++ b/modules/indicators/E1_ui.R @@ -24,7 +24,9 @@ tabItem(tabName = "E1_tab", br(), - tags$p("Below is a graph showing a comparison between health boards and NHS Scotland for your selected financial year."), + tags$p("Below is a graph showing a comparison between health boards and NHS Scotland for your selected financial year.", + br(), + "For ages 18 years and above"), # br(), fluidRow( @@ -39,9 +41,7 @@ tabItem(tabName = "E1_tab", ) ), br(), - tags$p("Source: Delayed discharges in NHS Scotland annual publication", - br(), - "For ages 18 years and above"), + tags$p("Source: Delayed discharges in NHS Scotland annual publication"), # as copied from above -- dataTableOutput("diagnoses_table"), br(), br(), From 388a547baa8e574b203d425bee389b5e36929cc3 Mon Sep 17 00:00:00 2001 From: MahriScot Date: Thu, 29 Aug 2024 15:47:33 +0100 Subject: [PATCH 39/75] E1 graph 1 scale taken away - will fix and add back next week --- modules/indicators/E1_server.R | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/indicators/E1_server.R b/modules/indicators/E1_server.R index bfbbf9e..a3dffdc 100644 --- a/modules/indicators/E1_server.R +++ b/modules/indicators/E1_server.R @@ -76,13 +76,14 @@ output$E1_plot1 <- renderPlotly({ color = "black", face = "bold"), legend.position = "none") + # removes legend - labs(x = "Financial Year", y = "Number of Days") + - scale_y_continuous(limits = c(0, (max(E1_data$dd_bed_days))), # Keeps the y-axis the same length for all graphs, ranges from 0 to the max value plus 9 so that the last tick can be seen - breaks = seq(0, (max(E1_data$dd_bed_days)), by = 10)) # y-axis ticks range from 0 to the max value + 9, showing increments of 10 + labs(x = "Financial Year", y = "Number of Days") #+ + #### TO FIX - will fix scale next week (MS 29/08) ---- + # scale_y_continuous(limits = c(0, (max(E1_data$dd_bed_days))), # Keeps the y-axis the same length for all graphs, ranges from 0 to the max value + # breaks = seq(0, (max(E1_data$dd_bed_days)), by = 2,000)) # y-axis ticks range from 0 to the max value, showing increments of 2,000 }) - - ### Run graph 1 through plotly ---- + + ### Run graph 1 through plotly ---- ggplotly(E1_plot1_graph(), tooltip = "text")#, # uses text set up in ggplot aes above. From 03a7528d0bd395a0a0b650cbc388b69b16d35f47 Mon Sep 17 00:00:00 2001 From: Cormac-Murray Date: Fri, 30 Aug 2024 11:17:36 +0100 Subject: [PATCH 40/75] Updates to page layout for EQ1 and EF5. --- modules/indicators/EF5_ui.R | 28 ++-- modules/indicators/EQ1_server.R | 2 +- modules/indicators/EQ1_ui.R | 231 +++++++++++++++++++++----------- 3 files changed, 170 insertions(+), 91 deletions(-) diff --git a/modules/indicators/EF5_ui.R b/modules/indicators/EF5_ui.R index 51f4562..3db532c 100644 --- a/modules/indicators/EF5_ui.R +++ b/modules/indicators/EF5_ui.R @@ -1,19 +1,28 @@ tabItem(tabName = "EF5_tab", fluidPage( - titlePanel("EF5 - % of did not attend appointments for community based services of people with mental health problems"), - mainPanel( - img(src='infographics/EF5.png', + h1("EF5 - % of did not attend appointments for community based services of people with mental health problems"), + fluidRow( + box(width = 9, + img(src='infographics/EF5.png', + #width = 250, height = 200, class = "infographic", alt = paste0( "The percentage of people who did not attend their ", "appointment for mental health problems at community based ", "services ranged from 8% to 19% for the quarter ending 30 ", "June 2023.")), - br(), - p("The data for EF5 is sourced is sourced from health board returns, which may be incomplete."), + ), + # box(width = 3, + # p("The data for EF5 is sourced is sourced from health board returns, which may be incomplete."), + # ), + ), - - fluidRow( + fluidRow( + box(width = 9, + p("The data for EF5 is sourced is sourced from health board returns, which may be incomplete."), + ), + ), + fluidRow( column(4, actionButton(inputId = "EF5_scot_hub_button", label = "Scotland Hub", icon = icon("home"), class = "navpageButton")), @@ -24,6 +33,5 @@ tabItem(tabName = "EF5_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of mainPanel - ) # End of fluidPage -) \ No newline at end of file + ) # End of fluidPage + ) diff --git a/modules/indicators/EQ1_server.R b/modules/indicators/EQ1_server.R index 03f4fb9..1d59b55 100644 --- a/modules/indicators/EQ1_server.R +++ b/modules/indicators/EQ1_server.R @@ -61,7 +61,7 @@ output$EQ1_plot1 <- renderPlotly({ plot_ly(data = EQ1_plot1_Data(), # Select your variables. - x = ~Year, y = ~risk_ratio, color = ~area_name, + x = ~as.factor(Year), y = ~risk_ratio, color = ~area_name, colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), text = tooltip_EQ1, hoverinfo = "text", type = 'scatter', mode = 'lines+markers', diff --git a/modules/indicators/EQ1_ui.R b/modules/indicators/EQ1_ui.R index 4bb769e..b564f82 100644 --- a/modules/indicators/EQ1_ui.R +++ b/modules/indicators/EQ1_ui.R @@ -1,86 +1,157 @@ tabItem(tabName = "EQ1_tab", fluidPage( - titlePanel(paste0( - "EQ1 - Premature mortality rate = Standardised mortality rate ", - "for persons in contact with mental health services")), - mainPanel( - tags$p("Below is a graph showing the changes over time."), - - fluidRow( - column(6,uiOutput("EQ1_plot1_areaType_output")), - column(6,uiOutput("EQ1_plot1_areaName_output")) + h1("EQ1 - Premature mortality rate = Standardised mortality rate ", + "for persons in contact with mental health services"), + fluidRow( + column(6, + box(width = NULL, + uiOutput("EQ1_plot1_areaType_output")) ), - - fluidRow( - plotlyOutput("EQ1_plot1" - # , - # width = "100%", - # height = "50%" - ) + column(6, + box(width = NULL, + uiOutput("EQ1_plot1_areaName_output")) ), - br(), - # br(), - # fluidRow( - # plotlyOutput("EQ1_plot2" - # # , - # # width = "100%", - # # height = "50%" - # ) - # ), - # br(), - # br(), - # fluidRow( - # plotlyOutput("EQ1_plot3" - # # , - # # width = "100%", - # # height = "50%" - # ) - # ), - # br(), - fluidRow( - column(6,uiOutput("EQ1_plot4_areaType_output")), - column(6,uiOutput("EQ1_plot4_areaName_output")) + ), + fluidRow( + column(12, + box(width = NULL, + p("Below is a graph showing the changes over time."))) ), - br(), - fluidRow( - plotlyOutput("EQ1_plot4" - # , - # width = "100%", - # height = "50%" - ) - ), - br(), - - - - br(), - - go_2_top_bttn, - - # tags$a(href = '#E1_top', - # icon("circle-arrow-up", - # lib = "glyphicon"), - # "Back to top"), - br(), - br(), - # ), # End of mainPanel - - - - - - fluidRow( - column(4, actionButton(inputId = "EQ1_scot_hub_button", - label = "Scotland Hub", icon = icon("home"), - class = "navpageButton")), - column(4, actionButton(inputId = "EF5_prevButton", - label = "Previous Page", icon = icon("arrow-left"), - class = "navpageButton")), - column(4, actionButton(inputId = "EQ2_nextButton", - label = "Next Page", icon = icon("arrow-right"), - class = "navpageButton")) - ) - ) # End of mainPanel - ) # End of fluidPage - ) + + fluidRow( + box(width = 12, + plotlyOutput("EQ1_plot1", + width = "100%")) + ), + fluidRow( + column(6, + box(width = NULL, + uiOutput("EQ1_plot4_areaType_output")) + ), + column(6, + box(width = NULL, + uiOutput("EQ1_plot4_areaName_output")) + ), + ), + br(), + fluidRow( + box(width = 12, + plotlyOutput("EQ1_plot4", + width = "100%")) + ), + + br(), + + go_2_top_bttn, + br(), + + fluidRow( + column(4, actionButton(inputId = "EQ1_scot_hub_button", + label = "Scotland Hub", icon = icon("home"), + class = "navpageButton")), + column(4, actionButton(inputId = "EF5_prevButton", + label = "Previous Page", icon = icon("arrow-left"), + class = "navpageButton")), + column(4, actionButton(inputId = "EQ2_nextButton", + label = "Next Page", icon = icon("arrow-right"), + class = "navpageButton")) + ) + + + + + ), # End of fluidPage +) + + + # titlePanel(paste0( + # "EQ1 - Premature mortality rate = Standardised mortality rate ", + # "for persons in contact with mental health services")), + + + + + + # mainPanel( + # tags$p("Below is a graph showing the changes over time."), + # + # fluidRow( + # column(6,uiOutput("EQ1_plot1_areaType_output")), + # column(6,uiOutput("EQ1_plot1_areaName_output")) + # ), + # + # fluidRow( + # plotlyOutput("EQ1_plot1" + # # , + # # width = "100%", + # # height = "50%" + # ) + # ), + # + # br(), + # # br(), + # # fluidRow( + # # plotlyOutput("EQ1_plot2" + # # # , + # # # width = "100%", + # # # height = "50%" + # # ) + # # ), + # # br(), + # # br(), + # # fluidRow( + # # plotlyOutput("EQ1_plot3" + # # # , + # # # width = "100%", + # # # height = "50%" + # # ) + # # ), + # # br(), + # fluidRow( + # column(6,uiOutput("EQ1_plot4_areaType_output")), + # column(6,uiOutput("EQ1_plot4_areaName_output")) + # ), + # br(), + # fluidRow( + # plotlyOutput("EQ1_plot4" + # # , + # # width = "100%", + # # height = "50%" + # ) + # ), + # br(), + # + # + # + # br(), + # + # go_2_top_bttn, + # + # # tags$a(href = '#E1_top', + # # icon("circle-arrow-up", + # # lib = "glyphicon"), + # # "Back to top"), + # br(), + # br(), + # # ), # End of mainPanel + # + # + # + # + # + # fluidRow( + # column(4, actionButton(inputId = "EQ1_scot_hub_button", + # label = "Scotland Hub", icon = icon("home"), + # class = "navpageButton")), + # column(4, actionButton(inputId = "EF5_prevButton", + # label = "Previous Page", icon = icon("arrow-left"), + # class = "navpageButton")), + # column(4, actionButton(inputId = "EQ2_nextButton", + # label = "Next Page", icon = icon("arrow-right"), + # class = "navpageButton")) + # ) + # ) # End of mainPanel + # ) # End of fluidPage + # ) + # From f2e40e5d2624a94586aa4781135ced44ebdd7d29 Mon Sep 17 00:00:00 2001 From: Cormac-Murray Date: Mon, 2 Sep 2024 14:47:54 +0100 Subject: [PATCH 41/75] Apply fluidRow changes to the Person-centred and Safe indicators, as well as adjust default font size for box text. --- modules/indicators/P1_ui.R | 44 ++++++++++++++++++-------------- modules/indicators/P2_ui.R | 45 ++++++++++++++++++--------------- modules/indicators/P3_ui.R | 44 ++++++++++++++++++-------------- modules/indicators/P4_ui.R | 34 +++++++++++++++++++------ modules/indicators/S1_ui.R | 43 +++++++++++++++++++------------- modules/indicators/S2_ui.R | 51 ++++++++++++++++++++++---------------- modules/indicators/S5_ui.R | 51 +++++++++++++++++++++----------------- www/stylesheet.css | 2 +- 8 files changed, 185 insertions(+), 129 deletions(-) diff --git a/modules/indicators/P1_ui.R b/modules/indicators/P1_ui.R index 0e2e471..bfc6cde 100644 --- a/modules/indicators/P1_ui.R +++ b/modules/indicators/P1_ui.R @@ -1,21 +1,28 @@ tabItem(tabName = "P1_tab", fluidPage( - titlePanel(paste0("P1 - % of carers with a mental health condition that ", - "felt supported to continue in their caring role")), - mainPanel( - img(src='infographics/P1.png', - class = "infographic", - alt = paste0( - "In Scotland in 2019/20 27% of carers with a mental health ", - "condition agreed that they felt asupported to continue caring. ", - "This compares with 30% of carers with a mental health condition ", - "in 2017/18")), - br(), - p("Further information can be found in the ", - a(href="https://www.gov.scot/collections/health-and-care-experience-survey/", - "Health and Care Experience Survey"), - "."), - + + h1("P1 - % of carers with a mental health condition that felt supported to continue in their caring role"), + fluidRow( + box(width = 9, + img(src='infographics/P1.png', + class = "infographic", + alt = paste0( + "In Scotland in 2019/20 27% of carers with a mental health ", + "condition agreed that they felt asupported to continue caring. ", + "This compares with 30% of carers with a mental health condition ", + "in 2017/18")), + ), + + ), + + fluidRow( + box(width = 9, + p("Further information can be found in the ", + a(href="https://www.gov.scot/collections/health-and-care-experience-survey/", + "Health and Care Experience Survey"),"."), + ), + ), + fluidRow( column(4, actionButton(inputId = "P1_scot_hub_button", label = "Scotland Hub", icon = icon("home"), @@ -27,6 +34,5 @@ tabItem(tabName = "P1_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of mainPanel - ) # End of fluidPage -) \ No newline at end of file + ) # End of fluidPage + ) diff --git a/modules/indicators/P2_ui.R b/modules/indicators/P2_ui.R index e140518..199540d 100644 --- a/modules/indicators/P2_ui.R +++ b/modules/indicators/P2_ui.R @@ -1,22 +1,28 @@ tabItem(tabName = "P2_tab", fluidPage( - titlePanel(paste0( - "P2 - % of adults with mental health problems supported at home ", - "who agree that their services and support had an impact in ", - "improving or maintaining their quality of life")), - mainPanel( - img(src='infographics/P2.png', - class = "infographic", - alt = paste0( - "In Scotland in 2019/20 27% of carers with a mental health ", - "condition agreed that they felt asupported to continue caring. ", - "This compares with 30% of carers with a mental health condition ", - "in 2017/18")), - br(), - p("Further information can be found in the ", - a(href="https://www.gov.scot/collections/health-and-care-experience-survey/", - "Health and Care Experience Survey"), - "."), + + h1("P2 - % of adults with mental health problems supported at home who agree that their services and support had an impact in improving or maintaining their quality of life"), + fluidRow( + box(width = 9, + img(src='infographics/P2.png', + class = "infographic", + alt = paste0( + "In Scotland in 2020/21 between 53% and 57% of adults ", + "with mental health problems supported at home agree that ", + "their services and support had an impact in improving ", + "or maintaining their quality of life. This compares with ", + "around 74% of adults with mental health problems in 2019/20.")), + ), + + ), + + fluidRow( + box(width = 9, + p("Further information can be found in the ", + a(href="https://www.gov.scot/collections/health-and-care-experience-survey/", + "Health and Care Experience Survey"),"."), + ), + ), fluidRow( column(4, actionButton(inputId = "P2_scot_hub_button", @@ -29,7 +35,6 @@ tabItem(tabName = "P2_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of mainPanel - ) # End of fluidPage + ) # End of fluidPage + ) -) \ No newline at end of file diff --git a/modules/indicators/P3_ui.R b/modules/indicators/P3_ui.R index 9cd5b6e..bb5dd0f 100644 --- a/modules/indicators/P3_ui.R +++ b/modules/indicators/P3_ui.R @@ -1,22 +1,29 @@ tabItem(tabName = "P3_tab", fluidPage( - titlePanel(paste0('P3 - % of replies for people with mental health ', - 'problem that agree with statement ', - '"people took account of the things that mattered to me"')), - mainPanel( - img(src='infographics/P3.png', - class = "infographic", - alt = paste0( - "In Scotland in 2019/20 78% of people with a mental health ", - "problem agreed that people took account of the things that ", - "mattered to them, compared to 80% of people with a mental ", - "health problem in 2017/18")), - br(), - p("Further information can be found in the ", - a(href="https://www.gov.scot/collections/health-and-care-experience-survey/", - "Health and Care Experience Survey"), - "."), + h1("P3 - % of replies for people with mental health problem that agree with statement 'people took account of the things that mattered to me'"), + fluidRow( + box(width = 9, + img(src='infographics/P3.png', + class = "infographic", + alt = paste0( + "In Scotland in 2019/20 78% of people with a mental health ", + "problem agreed that people took account of the things that ", + "mattered to them, compared to 80% of people with a mental ", + "health problem in 2017/18")), + ), + + ), + + fluidRow( + box(width = 9, + p("Further information can be found in the ", + a(href="https://www.gov.scot/collections/health-and-care-experience-survey/", + "Health and Care Experience Survey"),"."), + ), + ), + + # Navigation buttons fluidRow( column(4, actionButton(inputId = "P3_scot_hub_button", @@ -29,6 +36,5 @@ tabItem(tabName = "P3_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of mainPanel - ) # End of fluidPage -) \ No newline at end of file + ) # End of fluidPage + ) diff --git a/modules/indicators/P4_ui.R b/modules/indicators/P4_ui.R index 75dcfd4..77aca28 100644 --- a/modules/indicators/P4_ui.R +++ b/modules/indicators/P4_ui.R @@ -1,11 +1,30 @@ tabItem(tabName = "P4_tab", fluidPage( - titlePanel(paste0("P4 - Number of people with advance statements ", - "registered per year with the Mental Welfare ", - "Commission for Scotland")), - mainPanel( - p("This indicator has not been updated since 2021."), + + h1("P4 - Number of people with advance statements registered per year with the Mental Welfare Commission for Scotland"), + fluidRow( + box(width = 9, + img(src='infographics/P4.png', + class = "infographic", + alt = paste0( + "In Scotland in 2022/23, there were 155 new advanced ", + "statements registered with MWC, this compares with 117 ", + "new statements in 2021/22, 78 in 2020/21 and 257 in 2019/20.")), + ), + + ), + + fluidRow( + box(width = 9, + p("Further information can be found in the ", + a(href="https://www.gov.scot/collections/health-and-care-experience-survey/", + "Health and Care Experience Survey"),"."), + ), + ), + + + # Navigation buttons fluidRow( column(4, actionButton(inputId = "P4_scot_hub_button", @@ -18,6 +37,5 @@ tabItem(tabName = "P4_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of mainPanel - ) # End of fluidPage -) \ No newline at end of file + ) # End of fluidPage + ) diff --git a/modules/indicators/S1_ui.R b/modules/indicators/S1_ui.R index 005667c..1347678 100644 --- a/modules/indicators/S1_ui.R +++ b/modules/indicators/S1_ui.R @@ -1,19 +1,29 @@ tabItem(tabName = "S1_tab", fluidPage( - titlePanel("S1 - Suicide Rates per 100,000 population"), - mainPanel( - img(src='infographics/S1.png', - class = "infographic", - alt = paste0( - "For the five year period 2016 to 2020, the crude suicide ", - "rate per 100,000 population in Scotand was 13.7 compared to ", - "13.5 for the five year period 2011-2015.")), - br(), - p(paste0( - "Further information can be found in the [THIS LINK IS BROKEN]", - a(href="https://www.scotpho.org.uk/health-wellbeing-and-disease/suicide/key-points/", - "ScotPHO website"), - ".")), + + h1("S1 - Suicide Rates per 100,000 population"), + fluidRow( + box(width = 9, + img(src='infographics/S1.png', + class = "infographic", + alt = paste0( + "For the five year period 2016 to 2020, the crude suicide ", + "rate per 100,000 population in Scotand was 13.7 compared to ", + "13.5 for the five year period 2011-2015.")), + ), + + ), + + fluidRow( + box(width = 9, + p(paste0( + "Further information can be found in the [THIS LINK IS BROKEN]", + a(href="https://www.scotpho.org.uk/health-wellbeing-and-disease/suicide/key-points/", + "ScotPHO website"), + ".")), + ), + ), + fluidRow( column(4, actionButton(inputId = "S1_scot_hub_button", @@ -26,6 +36,5 @@ tabItem(tabName = "S1_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of mainPanel - ) # End of fluidPage -) \ No newline at end of file + ) # End of fluidPage + ) diff --git a/modules/indicators/S2_ui.R b/modules/indicators/S2_ui.R index 27d1f85..4dd4d2f 100644 --- a/modules/indicators/S2_ui.R +++ b/modules/indicators/S2_ui.R @@ -1,24 +1,32 @@ tabItem(tabName = "S2_tab", fluidPage( - titlePanel(paste0("S2 - % of all discharged psychiatric inpatients ", - "followed-up by community mental health services ", - "within 7 calendar days")), - mainPanel( - img(src='infographics/S2.png', - class = "infographic", - alt = paste0( - "For the quarter ending 31 December 2021, the percentage of ", - "discharged psychiatric inpatients followed-up by community ", - "mental health services within 7 calendar days ranged from ", - "17.6% to 88.1%")), - br(), - p(paste0( - "The data for S2 is sourced from board returns, which may be incomplete.")), - br(), - p(paste0( - "Board returns were received from NHS Ayrshire & Arran, NHS Borders, ", - "NHS Fife, NHS Forth Valley, NHS Grampian, NHS Greater Glasgow ", - "& Clyde, NHS Highland, NHS Lothian, NHS Tayside, and NHS Western Isles.")), + + h1("S2 - % of all discharged psychiatric inpatients followed-up by community mental health services within 7 calendar days"), + fluidRow( + box(width = 9, + img(src='infographics/S2.png', + class = "infographic", + alt = paste0( + "For the quarter ending 31 December 2021, the percentage of ", + "discharged psychiatric inpatients followed-up by community ", + "mental health services within 7 calendar days ranged from ", + "17.6% to 88.1%")), + ), + + ), + + fluidRow( + box(width = 9, + p(paste0( + "The data for S2 is sourced from board returns, which may be incomplete.")), + br(), + p(paste0( + "Board returns were received from NHS Ayrshire & Arran, NHS Borders, ", + "NHS Fife, NHS Forth Valley, NHS Grampian, NHS Greater Glasgow ", + "& Clyde, NHS Highland, NHS Lothian, NHS Tayside, and NHS Western Isles.")), + ), + ), + fluidRow( column(4, actionButton(inputId = "S2_scot_hub_button", @@ -31,6 +39,5 @@ tabItem(tabName = "S2_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of mainPanel - ) # End of fluidPage -) # End of tabItem \ No newline at end of file + ) # End of fluidPage + ) diff --git a/modules/indicators/S5_ui.R b/modules/indicators/S5_ui.R index b038762..dac1b6e 100644 --- a/modules/indicators/S5_ui.R +++ b/modules/indicators/S5_ui.R @@ -1,25 +1,31 @@ tabItem(tabName = "S5_tab", fluidPage( - titlePanel( - paste0( - "S5 - Incidents of physical violence per 1,000 occupied ", - "psychiatric bed days")), - mainPanel( - img(src='infographics/S5.png', - class = "infographic", - alt = paste0( - "The number of incidents of physical violence per 1,000 ", - "occupied psychiatric bed days in Scotland ranged from zero ", - "to 40.3 for the quarter ending 31 December 2021.")), - br(), - p(paste0( - "The data for S5 is sourced from board returns, which may be incomplete.")), - br(), - p(paste0( - "Board returns were received from NHS Ayrshire & Arran, NHS Borders, ", - "NHS Fife, NHS Forth Valley, NHS Grampian, NHS Greater Glasgow ", - "& Clyde, NHS Highland, NHS Lanarkshire, NHS Lothian, NHS Tayside, ", - "and NHS Western Isles.")), + + h1("S5 - Incidents of physical violence per 1,000 occupied psychiatric bed days"), + fluidRow( + box(width = 9, + img(src='infographics/S5.png', + class = "infographic", + alt = paste0( + "The number of incidents of physical violence per 1,000 ", + "occupied psychiatric bed days in Scotland ranged from zero ", + "to 40.3 for the quarter ending 31 December 2021.")), + ), + + ), + + fluidRow( + box(width = 9, + p(paste0( + "The data for S2 is sourced from board returns, which may be incomplete.")), + br(), + p(paste0( + "Board returns were received from NHS Ayrshire & Arran, NHS Borders, ", + "NHS Fife, NHS Forth Valley, NHS Grampian, NHS Greater Glasgow ", + "& Clyde, NHS Highland, NHS Lanarkshire, NHS Lothian, NHS Tayside, ", + "and NHS Western Isles.")), + ), + ), fluidRow( column(4, actionButton(inputId = "S5_scot_hub_button", @@ -32,6 +38,5 @@ tabItem(tabName = "S5_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of mainPanel - ) # End of fluidPage -) \ No newline at end of file + ) # End of fluidPage + ) diff --git a/www/stylesheet.css b/www/stylesheet.css index b6241fa..73545da 100755 --- a/www/stylesheet.css +++ b/www/stylesheet.css @@ -77,7 +77,7 @@ h1 { .box-body{ color: #3F3685; - font-size: 24px; /* Change this to your desired font size */ + font-size: 15px; /* Change this to your desired font size */ font-weight: bold; /*word-wrap: normal; /* tell css to wrap the text in buttons */ /*white-space: normal; /* required for text wrapping to work */ From ccb69cf51742613aaa275c02b5f35029c41573ee Mon Sep 17 00:00:00 2001 From: MahriScot Date: Tue, 3 Sep 2024 17:02:39 +0100 Subject: [PATCH 42/75] E1 plot 1 scale changed --- modules/indicators/E1_server.R | 18 ++++++++++-------- modules/indicators/E1_ui.R | 8 ++++---- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/modules/indicators/E1_server.R b/modules/indicators/E1_server.R index a3dffdc..bf7dcb5 100644 --- a/modules/indicators/E1_server.R +++ b/modules/indicators/E1_server.R @@ -37,6 +37,9 @@ E1_plot1_Data <- reactive({ & area_name %in% input$E1_plot1_areaName) }) +## Add different colours for 5 chosen options ---- + + # Create the discharges line chart ---- @@ -64,8 +67,8 @@ output$E1_plot1 <- renderPlotly({ E1_plot1_Data()$dd_bed_days) # for tooltip in ggplotly - shows values on hover ) ) + - geom_line(color = "black") + - geom_point(color = "black", fill = "black") + + geom_line(color = "#0080FF") + + geom_point(color = "#0080FF", fill = "#0080FF") + theme_classic() + # I normally use bw but will see what this looks like (de-clutters graph background) theme(panel.grid.major.x = element_line(), # Shows vertical grid lines panel.grid.major.y = element_line(), # Shows horizontal grid lines @@ -76,12 +79,11 @@ output$E1_plot1 <- renderPlotly({ color = "black", face = "bold"), legend.position = "none") + # removes legend - labs(x = "Financial Year", y = "Number of Days") #+ - #### TO FIX - will fix scale next week (MS 29/08) ---- - # scale_y_continuous(limits = c(0, (max(E1_data$dd_bed_days))), # Keeps the y-axis the same length for all graphs, ranges from 0 to the max value - # breaks = seq(0, (max(E1_data$dd_bed_days)), by = 2,000)) # y-axis ticks range from 0 to the max value, showing increments of 2,000 - - }) + labs(x = "Financial Year", y = "Total Number of Days") + + scale_y_continuous(expand = c(0, 0), # Ensures y axis starts from zero (important for Orkney and Shetland HBs which are all zero) + limits = c(0, (max(E1_plot1_Data()$dd_bed_days) + 0.5*max(E1_plot1_Data()$dd_bed_days)))) #, + # breaks = seq(0, (max(E1_plot1_Data()$dd_bed_days) + 0.5*max(E1_plot1_Data()$dd_bed_days)), by = 2500)) # Not good for Scotland total. Work on this? + }) ### Run graph 1 through plotly ---- diff --git a/modules/indicators/E1_ui.R b/modules/indicators/E1_ui.R index 1dd25fc..961618d 100644 --- a/modules/indicators/E1_ui.R +++ b/modules/indicators/E1_ui.R @@ -24,9 +24,7 @@ tabItem(tabName = "E1_tab", br(), - tags$p("Below is a graph showing a comparison between health boards and NHS Scotland for your selected financial year.", - br(), - "For ages 18 years and above"), + tags$p("Below is a graph showing a comparison between health boards and NHS Scotland for your selected financial year."), # br(), fluidRow( @@ -41,7 +39,9 @@ tabItem(tabName = "E1_tab", ) ), br(), - tags$p("Source: Delayed discharges in NHS Scotland annual publication"), + tags$p("Source: Delayed discharges in NHS Scotland annual publication.", + br(), + "Data shown is for ages 18 years and above"), # as copied from above -- dataTableOutput("diagnoses_table"), br(), br(), From 76a320d35e122e7b9b3d186a2db3af17521b7366 Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Wed, 4 Sep 2024 19:00:04 +0100 Subject: [PATCH 43/75] Updated E1 tab to use boxes --- modules/indicators/E1_ui.R | 171 +++++++++++++++++++++++++------------ 1 file changed, 116 insertions(+), 55 deletions(-) diff --git a/modules/indicators/E1_ui.R b/modules/indicators/E1_ui.R index 961618d..e3494f3 100644 --- a/modules/indicators/E1_ui.R +++ b/modules/indicators/E1_ui.R @@ -1,65 +1,125 @@ +### Beginning of E1 tab ---- + tabItem(tabName = "E1_tab", fluidPage( - titlePanel(paste0( - "E1 - Number of days people spend in hospital when they are ", - "clinically ready to be discharged (per 1,000 population)")), - mainPanel( - tags$p("Below is a graph showing the changes over time."), - - fluidRow( - column(6,uiOutput("E1_plot1_areaType_output")), - column(6,uiOutput("E1_plot1_areaName_output")) + ## Title for E1 tab ---- + h1(paste0( + "E1 - Delayed Discharges: Number of days people spend in hospital ", + "when they are clinically ready to be discharged (per 1,000 population)") ), - - fluidRow( - plotlyOutput("E1_plot1" - # , - # width = "100%", - # height = "50%" - ) + + ## First Graph ---- + # Text above graph + fluidRow( + column(12, + box(width = NULL, + p(paste0( + "Below is a graph showing the total number of days spent ", + "in hospital when patients are ready to be discharged over time, ", + "broken down by either council area of residence or health board of treatment. ", + "Use the drop down menus to select which areas you wish to look at.")) + ) + ) + ), # End of fluidRow + + # Drop down menus + fluidRow( + column(6, + box(width = NULL, + uiOutput("E1_plot1_areaType_output")) ), - br(), - # dataTableOutput("diagnoses_table"), - br(), - br(), - - - tags$p("Below is a graph showing a comparison between health boards and NHS Scotland for your selected financial year."), - # br(), - - fluidRow( - column(6,uiOutput("E1_plot2_year_output")) + column(6, + box(width = NULL, + uiOutput("E1_plot1_areaName_output")) ), - - fluidRow( - plotlyOutput("E1_plot2" - # , - # width = "100%", - # height = "50%" - ) - ), - br(), - tags$p("Source: Delayed discharges in NHS Scotland annual publication.", - br(), - "Data shown is for ages 18 years and above"), - # as copied from above -- dataTableOutput("diagnoses_table"), - br(), - br(), - - go_2_top_bttn, - - # tags$a(href = '#E1_top', - # icon("circle-arrow-up", - # lib = "glyphicon"), - # "Back to top"), - br(), - br(), - # ), # End of mainPanel + ), # End of fluidRow + + # Graph 1 output + fluidRow( + box(width = 12, + plotlyOutput("E1_plot1", + width = "100%")) + ), + br(), + hr(), # page break + br(), + ## Second Graph ---- + # Text above graph + fluidRow( + column(12, + box(width = NULL, + p(paste0( + "Below is a graph showing the total number of days spent ", + "in hospital when patients are ready to be discharged over time, ", + "broken down by either council area of residence or health board of treatment. ", + "Use the drop down menus to select which areas you wish to look at.")) + ) + ) + ), # End of fluidRow + # Year Drop down + fluidRow( + column(6, + box(width = NULL, + uiOutput("E1_plot2_year_output")) + ) + ), + # Graph 2 output + fluidRow( + box(width = 12, + plotlyOutput("E1_plot2", + width = "100%")) + ), + # mainPanel( + # tags$p("Below is a graph showing the changes over time."), + # + # fluidRow( + # column(6,uiOutput("E1_plot1_areaType_output")), + # column(6,uiOutput("E1_plot1_areaName_output")) + # ), + # + # fluidRow( + # plotlyOutput("E1_plot1" + # # , + # # width = "100%", + # # height = "50%" + # ) + # ), + # br(), + # # dataTableOutput("diagnoses_table"), + # br(), + # br(), + # + # + # tags$p("Below is a graph showing a comparison between health boards and NHS Scotland for your selected financial year."), + # # br(), + # + # fluidRow( + # column(6,uiOutput("E1_plot2_year_output")) + # ), + # + # fluidRow( + # plotlyOutput("E1_plot2" + # # , + # # width = "100%", + # # height = "50%" + # ) + # ), + # br(), + # tags$p("Source: Delayed discharges in NHS Scotland annual publication.", + # br(), + # "Data shown is for ages 18 years and above"), + # # as copied from above -- dataTableOutput("diagnoses_table"), + # br(), + # br(), + + br(), + + ## Navigation Buttons ---- fluidRow( column(4, actionButton(inputId = "E1_scot_hub_button", label = "Scotland Hub", icon = icon("home"), @@ -70,7 +130,8 @@ tabItem(tabName = "E1_tab", column(4, actionButton(inputId = "EF1_nextButton", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) - ) + ), + # Insert go to top button + go_2_top_bttn ) - ) -) + ) \ No newline at end of file From 443e4724c9cc27f57dff436b631826af14b4802e Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Thu, 5 Sep 2024 11:00:21 +0100 Subject: [PATCH 44/75] Removed bslib package --- app.R | 1 - 1 file changed, 1 deletion(-) diff --git a/app.R b/app.R index feb0508..8a68da9 100644 --- a/app.R +++ b/app.R @@ -13,7 +13,6 @@ library(fresh) # for customising shinydashboard look library(shinyWidgets) library(forcats) # added by mahri for fct_reorder() in graph library(gotop) -library(bslib) # Data import section ---------------------------------------------------- From b3c7c197b9415b9f9995d2f46317ccb8a885d991 Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Thu, 5 Sep 2024 11:28:20 +0100 Subject: [PATCH 45/75] Updated sidebar to include updated indicators --- modules/sidebar_ui.R | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/modules/sidebar_ui.R b/modules/sidebar_ui.R index de497c3..ebae03d 100644 --- a/modules/sidebar_ui.R +++ b/modules/sidebar_ui.R @@ -3,31 +3,33 @@ # link for external source, pic for image from old publication sidebarMenu( + # Enable scrolling of sidebar style = "height:94vh; overflow-y:auto; scrollbar-color: #9F9BC2 #3F3685;" , - # width: 300px;", # Enable scrolling of sidebar + # width: 300px;", + id = "tabs", + menuItem("Introduction", tabName = "intro", icon = icon("home"), selected = TRUE), menuItem("Scotland Hub", tabName = "scot_hub", icon = icon("globe")), br(), - + ## Timely Tabs ---- menuItem("Timely :", icon = icon("clock")), menuItem("T1 - Adult", tabName = "T1_tab", icon = icon("link")), menuItem("T2 - Child and Adolescent", tabName = "T2_tab", icon = icon("up-right-from-square")), menuItem("T3 - Drugs or Alcohol", tabName = "T3_tab", icon = icon("up-right-from-square")), br(), - + ## Safe Tabs ---- menuItem("Safe :"), menuItem("S1 - Suicide", tabName = "S1_tab", icon = icon("image")), - menuItem("S2 - Community Follow-up", tabName = "S2_tab", icon = icon("image"), - badgeLabel = "Updated", badgeColor = "orange"), + menuItem("S2 - Community Follow-up", tabName = "S2_tab", icon = icon("image")), menuItem("S5 - Physical Violence", tabName = "S5_tab", icon = icon("image")), br(), - + ## Person Tabs ---- menuItem("Person Centred :"), menuItem("P1 - Carers", tabName = "P1_tab", icon = icon("image")), menuItem("P2 - At Home Support", tabName = "P2_tab", icon = icon("image")), @@ -35,24 +37,26 @@ sidebarMenu( menuItem("P4 - Advance Statements", tabName = "P4_tab", icon = icon("image")), br(), - + ## Effective Tabs ---- menuItem("Effective :"), menuItem("E1 - Delayed Discharge", tabName = "E1_tab", icon = icon("bar-chart"), - badgeLabel = "New", badgeColor = "green"), + badgeLabel = "Updated", badgeColor = "orange"), br(), - + ## Efficient Tabs ---- menuItem("Efficient :"), menuItem("EF 1 - Emergency Bed Days", tabName = "EF1_tab", icon = icon("image")), menuItem("EF 2 - Readmissions", tabName = "EF2_tab", icon = icon("image")), menuItem("EF 3 - Psychiatric Beds", tabName = "EF3_tab", icon = icon("image")), - menuItem("EF 4 - Mental Health Spend", tabName = "EF4_tab", icon = icon("bar-chart")), + menuItem("EF 4 - Mental Health Spend", tabName = "EF4_tab", icon = icon("bar-chart"), + badgeLabel = "Updated", badgeColor = "orange"), menuItem("EF 5 - Community DNA", tabName = "EF5_tab", icon = icon("image")), br(), - + ## Equitable Tabs ---- menuItem("Equitable :"), - menuItem("EQ 1 - Premature Mortality", tabName = "EQ1_tab", icon = icon("bar-chart")), + menuItem("EQ 1 - Premature Mortality", tabName = "EQ1_tab", icon = icon("bar-chart"), + badgeLabel = "Updated", badgeColor = "orange"), menuItem("EQ 2 - Emergency Detention", tabName = "EQ2_tab", icon = icon("image")), menuItem("EQ 4 - U18 Outwith CAMH Wards", tabName = "EQ4_tab", icon = icon("image")) From aef51837f54673ecd98789a31fb80152391bf451 Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Thu, 5 Sep 2024 17:58:43 +0100 Subject: [PATCH 46/75] Added loading spinner to E1 graph 1 --- app.R | 9 +++++---- modules/indicators/E1_ui.R | 11 +++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app.R b/app.R index 8a68da9..e93a5bd 100644 --- a/app.R +++ b/app.R @@ -12,7 +12,8 @@ library(shinydashboard) library(fresh) # for customising shinydashboard look library(shinyWidgets) library(forcats) # added by mahri for fct_reorder() in graph -library(gotop) +library(gotop) # for return to top button +library(shinycssloaders) # for graph loading spinners # Data import section ---------------------------------------------------- @@ -44,13 +45,13 @@ ui <- dashboardPage( ## 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 ------------------------------- diff --git a/modules/indicators/E1_ui.R b/modules/indicators/E1_ui.R index e3494f3..26b37e3 100644 --- a/modules/indicators/E1_ui.R +++ b/modules/indicators/E1_ui.R @@ -37,8 +37,15 @@ tabItem(tabName = "E1_tab", # Graph 1 output fluidRow( box(width = 12, - plotlyOutput("E1_plot1", - width = "100%")) + withSpinner( + plotlyOutput("E1_plot1", width = "100%"), + color = "#AF69A9", + # color.background = "#E1C7DF", + type = 8, size = 0.7, + caption = "Loading...", + hide.ui = FALSE + ) + ) ), br(), From 489e4908696d2e69527ff82d96ed61d67711d87a Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Thu, 5 Sep 2024 18:09:34 +0100 Subject: [PATCH 47/75] Created phs_spinner function to apply spinner to all plots more easily --- functions/plot_functions.R | 16 +++++++++++++++- modules/indicators/E1_ui.R | 9 +-------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/functions/plot_functions.R b/functions/plot_functions.R index e9e061e..e9bcda5 100755 --- a/functions/plot_functions.R +++ b/functions/plot_functions.R @@ -1,4 +1,18 @@ -# No Data function ---- +### 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){ diff --git a/modules/indicators/E1_ui.R b/modules/indicators/E1_ui.R index 26b37e3..b519a5f 100644 --- a/modules/indicators/E1_ui.R +++ b/modules/indicators/E1_ui.R @@ -37,14 +37,7 @@ tabItem(tabName = "E1_tab", # Graph 1 output fluidRow( box(width = 12, - withSpinner( - plotlyOutput("E1_plot1", width = "100%"), - color = "#AF69A9", - # color.background = "#E1C7DF", - type = 8, size = 0.7, - caption = "Loading...", - hide.ui = FALSE - ) + phs_spinner("E1_plot1") ) ), From e27310753ca1e79a12ca07eeed8938c577230f83 Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Thu, 5 Sep 2024 18:11:18 +0100 Subject: [PATCH 48/75] Added spinner to E1 graph 2 --- modules/indicators/E1_ui.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/indicators/E1_ui.R b/modules/indicators/E1_ui.R index b519a5f..3e12ffc 100644 --- a/modules/indicators/E1_ui.R +++ b/modules/indicators/E1_ui.R @@ -69,8 +69,8 @@ tabItem(tabName = "E1_tab", # Graph 2 output fluidRow( box(width = 12, - plotlyOutput("E1_plot2", - width = "100%")) + phs_spinner("E1_plot2") + ) ), From 316f9a25f0fff481f442abe5c1f2fbded414e10c Mon Sep 17 00:00:00 2001 From: Cormac-Murray Date: Fri, 6 Sep 2024 13:33:18 +0100 Subject: [PATCH 49/75] Apply fluidRow to all remaining pages with infographics. --- modules/indicators/EF1_ui.R | 17 ++++++++++------- modules/indicators/EF2_ui.R | 7 ++++--- modules/indicators/EF3_ui.R | 17 +++++++++++------ modules/indicators/EQ1_ui.R | 6 ++---- modules/indicators/EQ2_ui.R | 19 ++++++++++++------- modules/indicators/EQ4_ui.R | 18 ++++++++++++------ modules/indicators/T1_ui.R | 11 +++++++---- modules/indicators/T2_ui.R | 20 ++++++++++++-------- modules/indicators/T3_ui.R | 28 +++++++++++++++------------- 9 files changed, 85 insertions(+), 58 deletions(-) diff --git a/modules/indicators/EF1_ui.R b/modules/indicators/EF1_ui.R index 1b29553..92050d0 100644 --- a/modules/indicators/EF1_ui.R +++ b/modules/indicators/EF1_ui.R @@ -1,8 +1,8 @@ tabItem(tabName = "EF1_tab", fluidPage( - titlePanel("EF1 - Rate of Emergency Bed Days for Adults"), - - mainPanel( + h1("EF1 - Rate of Emergency Bed Days for Adults"), + fluidRow( + box(width = 9, img(src='infographics/EF1.png', class = "infographic", alt = paste0( @@ -11,7 +11,10 @@ tabItem(tabName = "EF1_tab", "per 100,000 population in Scotland for the year-long period ", "ending 30 September 2021, compared to 19,078 per 100,000 ", "population for the year ending 30 September 2020.")), - br(), + ) + ), + fluidRow( + box(width = 9, p("The data for EF1 is sourced from ", a(href="https://www.nssdiscovery.scot.nhs.uk/", "Discovery"), @@ -19,6 +22,8 @@ tabItem(tabName = "EF1_tab", a(href="https://publichealthscotland.scot/services/data-management/data-management-in-secondary-care-hospital-activity/scottish-morbidity-records-smr/completeness/", "Data completeness"), " for SMR04 was around 90% or better when the data was accessed."), + ) + ), fluidRow( column(4, actionButton(inputId = "EF1_scot_hub_button", @@ -31,7 +36,5 @@ tabItem(tabName = "EF1_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of mainPanel ) # End of fluidPage - -) \ No newline at end of file + ) diff --git a/modules/indicators/EF2_ui.R b/modules/indicators/EF2_ui.R index b02d173..cfd820f 100644 --- a/modules/indicators/EF2_ui.R +++ b/modules/indicators/EF2_ui.R @@ -2,7 +2,7 @@ tabItem(tabName = "EF2_tab", fluidPage( h1("EF2 - Readmissions to hospital within 28 days of discharge"), fluidRow( - box(width = NULL, + box(width = 9, img(src='infographics/EF2.png', class = c("infographic", "box"), alt = paste0( @@ -13,8 +13,9 @@ tabItem(tabName = "EF2_tab", ), - - box(width = NULL, + ), + fluidRow( + box(width = 9, p("The data for EF1 is sourced from ", a(href="https://www.nssdiscovery.scot.nhs.uk/", "Discovery"), diff --git a/modules/indicators/EF3_ui.R b/modules/indicators/EF3_ui.R index 8759a8e..14f0750 100644 --- a/modules/indicators/EF3_ui.R +++ b/modules/indicators/EF3_ui.R @@ -1,7 +1,8 @@ tabItem(tabName = "EF3_tab", fluidPage( - titlePanel("EF3 - Total psychiatric inpatient beds per 100,000 population (NRAC adjusted)"), - mainPanel( + h1("EF3 - Total psychiatric inpatient beds per 100,000 population (NRAC adjusted)"), + fluidRow( + box(width = 9, img(src='infographics/EF3.png', class = "infographic", alt = paste0( @@ -11,13 +12,18 @@ tabItem(tabName = "EF3_tab", "population). This is a decrease from 67.5 beds per 100,000 ", "population in 2021/22 and 68.8 beds per 100,000 population ", "in 2020/21.")), - br(), + ) + ), + fluidRow( + box(width = 9, p("The numerator for EF3 is sourced from ", a(href="https://publichealthscotland.scot/publications/acute-hospital-activity-and-nhs-beds-information-annual/", "the Acute hospital activity and NHS beds information annual release publication, "), "and the denominator is sourced from ", a(href="https://www.publichealthscotland.scot/publications/resource-allocation-formula-nrac/resource-allocation-formula-nrac-for-nhsscotland-results-for-financial-year-2024-to-2025/", "the National Resource Allocation publication.")), + ) + ), fluidRow( column(4, actionButton(inputId = "EF3_scot_hub_button", @@ -30,7 +36,6 @@ tabItem(tabName = "EF3_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of mainPanel - ) # End of fluidPage + ) # End of fluidPage + ) -) \ No newline at end of file diff --git a/modules/indicators/EQ1_ui.R b/modules/indicators/EQ1_ui.R index b564f82..6947f7b 100644 --- a/modules/indicators/EQ1_ui.R +++ b/modules/indicators/EQ1_ui.R @@ -20,8 +20,7 @@ tabItem(tabName = "EQ1_tab", fluidRow( box(width = 12, - plotlyOutput("EQ1_plot1", - width = "100%")) + phs_spinner("EQ1_plot1")) ), fluidRow( column(6, @@ -36,8 +35,7 @@ tabItem(tabName = "EQ1_tab", br(), fluidRow( box(width = 12, - plotlyOutput("EQ1_plot4", - width = "100%")) + phs_spinner("EQ1_plot4")) ), br(), diff --git a/modules/indicators/EQ2_ui.R b/modules/indicators/EQ2_ui.R index 88e5f88..a593b7f 100644 --- a/modules/indicators/EQ2_ui.R +++ b/modules/indicators/EQ2_ui.R @@ -1,17 +1,22 @@ tabItem(tabName = "EQ2_tab", fluidPage( - titlePanel("EQ2 - Number of emergency detention certificates (EDCs) per 100,000 population"), - mainPanel( + h1("EQ2 - Number of emergency detention certificates (EDCs) per 100,000 population"), + fluidRow( + box(width = 9, img(src='infographics/EQ2.png', class = "infographic", alt = paste0( "In Scotland in 2022/23, the number of emergency detention ", "certificates per 100,000 population was 60.0. This is a ", - "slight increase from 59.5 in 2021/22.")), - br(), + "slight increase from 59.5 in 2021/22.")),) + ), + fluidRow( + box(width = 9, p("This data is sourced from the ", a(href="https://www.mwcscot.org.uk/publications?type=44&leg=54", "Mental Welfare Commission.")), + ) + ), fluidRow( column(4, actionButton(inputId = "EQ2_scot_hub_button", @@ -24,6 +29,6 @@ tabItem(tabName = "EQ2_tab", label = "Next Page", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of mainPanel - ) # End of fluidPage - ) \ No newline at end of file + ) # End of fluidPage + ) + \ No newline at end of file diff --git a/modules/indicators/EQ4_ui.R b/modules/indicators/EQ4_ui.R index 4e403ab..5272416 100644 --- a/modules/indicators/EQ4_ui.R +++ b/modules/indicators/EQ4_ui.R @@ -1,7 +1,8 @@ tabItem(tabName = "EQ4_tab", fluidPage( - titlePanel("EQ4 - % of under 18 year old psychiatric admissions admitted out with NHS specialist Child and Adolescent Mental Health (CAMH) wards"), - mainPanel( + h1("EQ4 - % of under 18 year old psychiatric admissions admitted out with NHS specialist Child and Adolescent Mental Health (CAMH) wards"), + fluidRow( + box(width = 9, img(src='infographics/EQ4.png', class = "infographic", alt = paste0( @@ -10,10 +11,15 @@ tabItem(tabName = "EQ4_tab", "year-long period ending 31 March 2023. This compares with ", "35.5% during the year ending 31 March 2022, and 29.3% ", "during the year ending 31 March 2021.")), - br(), + ) + ), + fluidRow( + box(width = 9, p("The data for EQ4 is sourced from ", a(href="https://www.publichealthscotland.scot/services/discovery/#section-1-1", "Discovery.")), + ) + ), fluidRow( column(4, actionButton(inputId = "EQ2_prevButton", @@ -23,6 +29,6 @@ tabItem(tabName = "EQ4_tab", label = "Scotland Hub", icon = icon("home"), class = "navpageButton")) ) - ) # End of mainPanel - ) # End of fluidPage - ) \ No newline at end of file + ) # End of fluidPage + ) + \ No newline at end of file diff --git a/modules/indicators/T1_ui.R b/modules/indicators/T1_ui.R index 779fd50..538366d 100644 --- a/modules/indicators/T1_ui.R +++ b/modules/indicators/T1_ui.R @@ -1,8 +1,9 @@ tabItem(tabName = "T1_tab", fluidPage( h1("T1 - % of people who commence Psychological therapy based treatment within 18 weeks of referral"), - h2("Last Updated: Septemberr 2023"), - box(width = 12, + h2("Last Updated: September 2023"), + fluidRow( + box(width = 9, img(src='infographics/T1.png', class = "infographic", alt = paste0( @@ -11,13 +12,15 @@ tabItem(tabName = "T1_tab", "compared to 87.2% for the previous quarter, and 80% for the ", "quarter ending 31 December 2020")) ), - - box(width = 12, + ), + fluidRow( + box(width = 9, p("Further information can be found in the ", a(href="https://publichealthscotland.scot/publications/psychological-therapies-waiting-times/", "Psychological Therapies Waiting Times publication"), ".") ), + ), fluidRow( column(4, actionButton(inputId = "T1_scot_hub_button", label = "Scotland Hub", icon = icon("home"), diff --git a/modules/indicators/T2_ui.R b/modules/indicators/T2_ui.R index 7591c9d..459f643 100644 --- a/modules/indicators/T2_ui.R +++ b/modules/indicators/T2_ui.R @@ -1,10 +1,10 @@ tabItem(tabName = "T2_tab", fluidPage( - headerPanel(fluidRow("T2 - % of young people who commence treatment by + h1("T2 - % of young people who commence treatment by specialist Child and Adolescent Mental Health services - within 18 weeks of referral", - "Sub title")), - mainPanel( + within 18 weeks of referral"), + fluidRow( + box(width = 9, img(src='infographics/T2.png', class = "infographic", alt = paste0( @@ -14,11 +14,16 @@ tabItem(tabName = "T2_tab", "previous quarter, and 73.1% in the quarter ending 31 December 2020. ", "Half of children and young people started treatment within seven ", "weeks in the quarter ending 31 December 2021")), - br(), + ) + ), + fluidRow( + box(width = 9, p("Further information can be found in the ", a(href="https://publichealthscotland.scot/publications/child-and-adolescent-mental-health-services-camhs-waiting-times/", "Child and Adolescent Mental Health Services in Scotland: Waiting Times publication"), "."), + ) + ), fluidRow( column(4, actionButton(inputId = "T2_scot_hub_button", label = "Scotland Hub", icon = icon("home"), @@ -30,6 +35,5 @@ tabItem(tabName = "T2_tab", label = "Next Page: T3", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of mainPanel - ) # End of fluidPage -) \ No newline at end of file + ) # End of fluidPage + ) diff --git a/modules/indicators/T3_ui.R b/modules/indicators/T3_ui.R index 3a614e9..4bb0a09 100644 --- a/modules/indicators/T3_ui.R +++ b/modules/indicators/T3_ui.R @@ -1,11 +1,10 @@ tabItem(tabName = "T3_tab", fluidPage( - titlePanel( - paste0( - "T3 - % of people who wait less than three weeks from referral ", + h1("T3 - % of people who wait less than three weeks from referral ", "received to appropriate drug or alcohol treatment that supports ", - "their recovery")), - mainPanel( + "their recovery"), + fluidRow( + box(width = 9, img(src='infographics/T3.png', class = "infographic", alt = paste0( @@ -13,15 +12,19 @@ tabItem(tabName = "T3_tab", "drug and aclohol treatment services completed in the quarter ", "ending 31 December 2021, 93% involved a wait of three weeks or ", "less. The percentage of referrals completed within three weeks ", - "for drug treatment was 94% and 92% for alcohol treatment.")), - br(), - p(paste0( + "for drug treatment was 94% and 92% for alcohol treatment.")) + ) + ), + fluidRow( + box(width = 9, + p(paste0( "Data from City of Edinburgh Alcohol and Drug Partnership (ADP) ", "have been excluded from this release as the ADP was unable to ", "confirm that their data were accurate and up-to-date within the ", "specified timescale. Amongst the remaining ADPs, 13 services out ", - "of 181 were excluded due to the absence of complete data.") - ), + "of 181 were excluded due to the absence of complete data.")), + ) + ), br(), p("Further information can be found in the ", a(href="https://beta.isdscotland.org/find-publications-and-data/lifestyle-and-behaviours/substance-use/national-drug-and-alcohol-treatment-waiting-times/", @@ -38,6 +41,5 @@ tabItem(tabName = "T3_tab", label = "Next Page: S1", icon = icon("arrow-right"), class = "navpageButton")) ) - ) # End of mainPanel - ) # End of fluidPage -) \ No newline at end of file + ) # End of fluidPage + ) From 07d2a095d8c262554e24257cef48c92946aa40bd Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Mon, 9 Sep 2024 16:04:36 +0100 Subject: [PATCH 50/75] Added package text for purrr --- app.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.R b/app.R index e93a5bd..c23740b 100644 --- a/app.R +++ b/app.R @@ -5,7 +5,7 @@ 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) From f552716473908d772830f5ed0d24ee80aed834fa Mon Sep 17 00:00:00 2001 From: Cormac-Murray Date: Tue, 17 Sep 2024 15:23:50 +0100 Subject: [PATCH 51/75] Updates to E1 chart selection and lines. --- modules/indicators/E1_server.R | 75 +++++++++++++++++++++++----------- modules/indicators/E1_ui.R | 10 +++++ 2 files changed, 61 insertions(+), 24 deletions(-) diff --git a/modules/indicators/E1_server.R b/modules/indicators/E1_server.R index bf7dcb5..b5151de 100644 --- a/modules/indicators/E1_server.R +++ b/modules/indicators/E1_server.R @@ -15,16 +15,16 @@ output$E1_plot1_areaType_output <- renderUI({ output$E1_plot1_areaName_output <- renderUI({ shinyWidgets::pickerInput( "E1_plot1_areaName", - label = "Select area(s) (Maximum 5):", + label = "Select area(s) (Maximum 4):", selected = "NHS Ayrshire & Arran", choices = sort(unique(as.character( E1_data$area_name [E1_data$area_type %in% input$E1_plot1_areaType] ))) - # , - # multiple = TRUE, - # options = list("max-options" = 5, - # `selected-text-format` = "count > 1") + , + multiple = TRUE, + options = list("max-options" = 4, + `selected-text-format` = "count > 1") ) }) @@ -57,6 +57,8 @@ output$E1_plot1 <- renderPlotly({ y = dd_bed_days, group = area_name, color = area_name, + linetype = area_name, + shape = area_name, text = paste0("Financial year: ", E1_plot1_Data()$fyear, "
", @@ -64,26 +66,51 @@ output$E1_plot1 <- renderPlotly({ E1_plot1_Data()$area_name, "
", "Total number of bed days: ", - E1_plot1_Data()$dd_bed_days) # for tooltip in ggplotly - shows values on hover - ) + E1_plot1_Data()$dd_bed_days), # for tooltip in ggplotly - shows values on hover + ) ) + - geom_line(color = "#0080FF") + - geom_point(color = "#0080FF", fill = "#0080FF") + - theme_classic() + # I normally use bw but will see what this looks like (de-clutters graph background) - theme(panel.grid.major.x = element_line(), # Shows vertical grid lines - panel.grid.major.y = element_line(), # Shows horizontal grid lines - axis.title.x = element_text(size = 12, - color = "black", - face = "bold"), - axis.title.y = element_text(size = 12, - color = "black", - face = "bold"), - legend.position = "none") + # removes legend - labs(x = "Financial Year", y = "Total Number of Days") + - scale_y_continuous(expand = c(0, 0), # Ensures y axis starts from zero (important for Orkney and Shetland HBs which are all zero) - limits = c(0, (max(E1_plot1_Data()$dd_bed_days) + 0.5*max(E1_plot1_Data()$dd_bed_days)))) #, - # breaks = seq(0, (max(E1_plot1_Data()$dd_bed_days) + 0.5*max(E1_plot1_Data()$dd_bed_days)), by = 2500)) # Not good for Scotland total. Work on this? - }) + geom_line() + + guides(linetype = "none", shape = "none", color = guide_legend(title = "Area name", nrow = 2)) + + scale_color_manual(values = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), + labels = ~ stringr::str_wrap(.x, width = 15)) + + scale_linetype_manual(values = c("solid", "dashed", "solid", "dashed")) + + geom_point(size = 2.5) + + scale_shape_manual(values = c("circle", "circle", "triangle-up", "triangle-up")) + + theme_classic() + # I normally use bw but will see what this looks like (de-clutters graph background) + theme(panel.grid.major.x = element_line(), # Shows vertical grid lines + panel.grid.major.y = element_line(), # Shows horizontal grid lines + axis.title.x = element_text(size = 12, + color = "black", + face = "bold"), + axis.title.y = element_text(size = 12, + color = "black", + face = "bold")) + # removes legend + labs(x = "Financial Year", y = "Total Number of Days") + + scale_y_continuous(expand = c(0, 0), # Ensures y axis starts from zero (important for Orkney and Shetland HBs which are all zero) + limits = c(0, (max(E1_plot1_Data()$dd_bed_days) + 0.5*max(E1_plot1_Data()$dd_bed_days)))) #, + # breaks = seq(0, (max(E1_plot1_Data()$dd_bed_days) + 0.5*max(E1_plot1_Data()$dd_bed_days)), by = 2500)) # Not good for Scotland total. Work on this? + }) + + + # + # geom_line() + + # scale_color_manual(values = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2", "#E6F2FB"))+ + # geom_point(color = "#0080FF", fill = "#0080FF") + + # theme_classic() + # I normally use bw but will see what this looks like (de-clutters graph background) + # theme(panel.grid.major.x = element_line(), # Shows vertical grid lines + # panel.grid.major.y = element_line(), # Shows horizontal grid lines + # axis.title.x = element_text(size = 12, + # color = "black", + # face = "bold"), + # axis.title.y = element_text(size = 12, + # color = "black", + # face = "bold")+ # , + # legend.position = "none") + # removes legend + # labs(x = "Financial Year", y = "Total Number of Days") + + # scale_y_continuous(expand = c(0, 0), # Ensures y axis starts from zero (important for Orkney and Shetland HBs which are all zero) + # limits = c(0, (max(E1_plot1_Data()$dd_bed_days) + 0.5*max(E1_plot1_Data()$dd_bed_days)))) #, + # # breaks = seq(0, (max(E1_plot1_Data()$dd_bed_days) + 0.5*max(E1_plot1_Data()$dd_bed_days)), by = 2500)) # Not good for Scotland total. Work on this? + # }) ### Run graph 1 through plotly ---- diff --git a/modules/indicators/E1_ui.R b/modules/indicators/E1_ui.R index 3e12ffc..0e8452e 100644 --- a/modules/indicators/E1_ui.R +++ b/modules/indicators/E1_ui.R @@ -2,6 +2,16 @@ tabItem(tabName = "E1_tab", fluidPage( + tags$head( + tags$style( + type = "text/css", + + # Prevent error messages from popping up on the interface. + ".shiny-output-error { visibility: hidden; }", + ".shiny-output-error:before { visibility: hidden; }" + + ), + ), ## Title for E1 tab ---- h1(paste0( "E1 - Delayed Discharges: Number of days people spend in hospital ", From 2a3f96e306667c8ad47cb48bab516e45e59910af Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Fri, 20 Sep 2024 12:56:30 +0100 Subject: [PATCH 52/75] Various css adjustments to Scotland Hub Tab --- modules/scot_hub_ui.R | 34 ++++++++-------------------------- www/stylesheet.css | 28 +++++++++++++++++++++------- 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/modules/scot_hub_ui.R b/modules/scot_hub_ui.R index 8840bf6..50d82fb 100644 --- a/modules/scot_hub_ui.R +++ b/modules/scot_hub_ui.R @@ -7,17 +7,21 @@ tabItem(tabName = "scot_hub", box(## T1 ---- # Header Text title = tagList(icon("brain"), - paste0( + # N.B. using paste0 for all text blocks rather than writing out the text + # in one go so that there isn't a new line tag inserted when converting R + # to HTML, which screenreaders would read out + paste0( "T1 - % of people who commence psychological ", "therapy based treatment within 18 weeks of referral ", T1_dateText,":")), - width = 4, solidHeader = TRUE, + width = 4, solidHeader = TRUE, # Body text paste0(T1,"%"), # Navigation button actionButton(inputId = "T1_button", label = "T1 - Find out more", - class = "navpageButton pull-right") + class = "navpageButton pull-right") + # N.B. pull-right class keeps the actionButton aligned right but within the box boundaries ), box(## T2 ---- @@ -162,14 +166,7 @@ tabItem(tabName = "scot_hub", actionButton(inputId = "P3_button", label = "P3 - Find out more", class = "navpageButton pull-right") - ) - ), - - # No br() as the next row is the same category - - ### [Person Centred 2] --------------------------- - - fluidRow( + ), box(## P4 ---- # Header Text @@ -255,14 +252,7 @@ tabItem(tabName = "scot_hub", actionButton(inputId = "EF3_button", label = "EF3 - Find out more", class = "navpageButton pull-right") - ) ), - - # No br() as the next row is the same category - - ### [Efficient 2] --------------------------- - - fluidRow( box(# EF4 ---- # Header Text @@ -348,14 +338,6 @@ tabItem(tabName = "scot_hub", ), - ), - - # No br() as the next row is the same category - - ### [Equitable 2] --------------------------- - - fluidRow( - box(## EQ4 ---- # Header Text title = tagList(icon("hourglass-end"), diff --git a/www/stylesheet.css b/www/stylesheet.css index 73545da..a8680cb 100755 --- a/www/stylesheet.css +++ b/www/stylesheet.css @@ -11,6 +11,7 @@ /*align: right;*/ } + /* Main header*/ /*.main-header .navbar { background-color: #ECEBF3; /* Header colour */ @@ -60,24 +61,37 @@ h1 { /* [ScotHub styling] */ /* Defining shinydashboard 'box' element styling */ + +/* Whole Box */ +.col-sm-4{ + min-width: 400px; +} +/* +.box .box-solid{ + width: 400px; +}*/ + +/* Header */ .box-header{ - background-color: #ECEBF3; /* Header colour */ - color: #3F3685; /* Header text colour */ + background-color: #3F3685; /* Header colour */ + color: #ECEBF3; /* Header text colour */ /*font-weight: bold;*/ word-wrap: normal; /* tell css to wrap the text in buttons */ white-space: normal; /* required for text wrapping to work */ - + height: 90px; /* Specifying height of Header area */ } +/* Box Header Text */ .box-header h3{ - /*font-size: 36px;*/ - font-weight: bold; - line-height: 1.8; + /* font-weight: bold; */ + + font-size: 36px; + /*line-height: 3; Doesn't seem to change anything */ } .box-body{ color: #3F3685; - font-size: 15px; /* Change this to your desired font size */ + font-size: 20px; /* Change this to your desired font size */ font-weight: bold; /*word-wrap: normal; /* tell css to wrap the text in buttons */ /*white-space: normal; /* required for text wrapping to work */ From b87d93de3782522f5ba3f60c750183de94bc7a92 Mon Sep 17 00:00:00 2001 From: MahriScot Date: Wed, 25 Sep 2024 14:32:56 +0100 Subject: [PATCH 53/75] EF4 graph changed to ggplot and run through plotly. E1 graph2 title changed to reflect "per 1,000 population" --- modules/indicators/E1_server.R | 22 +-- modules/indicators/E1_ui.R | 4 +- modules/indicators/EF4_server.R | 334 ++++++++++++++++++++------------ modules/indicators/EF4_ui.R | 17 +- 4 files changed, 235 insertions(+), 142 deletions(-) diff --git a/modules/indicators/E1_server.R b/modules/indicators/E1_server.R index b5151de..d89a6c1 100644 --- a/modules/indicators/E1_server.R +++ b/modules/indicators/E1_server.R @@ -16,14 +16,13 @@ output$E1_plot1_areaName_output <- renderUI({ shinyWidgets::pickerInput( "E1_plot1_areaName", label = "Select area(s) (Maximum 4):", - selected = "NHS Ayrshire & Arran", choices = sort(unique(as.character( E1_data$area_name [E1_data$area_type %in% input$E1_plot1_areaType] - ))) - , - multiple = TRUE, - options = list("max-options" = 4, + ))), + selected = "NHS Ayrshire & Arran", + multiple = TRUE, + options = list("max-options" = 4, `selected-text-format` = "count > 1") ) }) @@ -43,8 +42,6 @@ E1_plot1_Data <- reactive({ # Create the discharges line chart ---- -## Testing new code ---- - ### Render plotly ---- output$E1_plot1 <- renderPlotly({ @@ -84,7 +81,7 @@ output$E1_plot1 <- renderPlotly({ face = "bold"), axis.title.y = element_text(size = 12, color = "black", - face = "bold")) + # removes legend + face = "bold")) + labs(x = "Financial Year", y = "Total Number of Days") + scale_y_continuous(expand = c(0, 0), # Ensures y axis starts from zero (important for Orkney and Shetland HBs which are all zero) limits = c(0, (max(E1_plot1_Data()$dd_bed_days) + 0.5*max(E1_plot1_Data()$dd_bed_days)))) #, @@ -315,16 +312,15 @@ E1_plot2_Data <- reactive({ filter(fyear %in% input$E1_plot2_year) %>% mutate(area_name = fct_reorder(area_name, rate_per_1000_population)) %>% # for ordering by most to least bed days mutate(to_highlight = if_else(area_name == "NHS Scotland", # for highlighting NHS Scotland - "seagreen", "#0080FF")) # changed from "yes" and "no" so that these colours appear on the graph and don't have a legend using "marker = list(color... )" -}) # only using "seagreen" to make sure it is working for now + "seagreen", "#0080FF")) # changed from "yes" and "no" so that these colours +}) # appear on the graph and don't have a legend using "marker = list(color... )" + # Note: only using "seagreen" to make sure it is working for now, can change colour later # Create the discharges bar chart ---- - ## Testing new code ---- - - ### Render plotly ---- + ### Render plotly ---- output$E1_plot2 <- renderPlotly({ diff --git a/modules/indicators/E1_ui.R b/modules/indicators/E1_ui.R index 0e8452e..b3be1a7 100644 --- a/modules/indicators/E1_ui.R +++ b/modules/indicators/E1_ui.R @@ -61,8 +61,8 @@ tabItem(tabName = "E1_tab", column(12, box(width = NULL, p(paste0( - "Below is a graph showing the total number of days spent ", - "in hospital when patients are ready to be discharged over time, ", + "Below is a graph showing the total number of days, per 1,000 population, ", + "spent in hospital when patients are ready to be discharged over time, ", "broken down by either council area of residence or health board of treatment. ", "Use the drop down menus to select which areas you wish to look at.")) ) diff --git a/modules/indicators/EF4_server.R b/modules/indicators/EF4_server.R index 3005a9a..834d52d 100644 --- a/modules/indicators/EF4_server.R +++ b/modules/indicators/EF4_server.R @@ -27,137 +27,219 @@ EF4_trendPlot_data <- reactive({ measure %in% input$EF4_trendPlot_measure) }) -## plotly bar chart ---- -output$EF4_trendPlot <- renderPlotly({ - # - # # # No data plot - # # if(sum(EF4_trendPlot_data()$value) == 0 & - # # !is.na(sum(EF4_trendPlot_data()$value))) - # # - # # { - # # noDataPlot(phs_colours("phs-purple")) - # # } - # # - # # else { - # - ### Tooltip creation ---- - tooltip_EF4 <- paste0("Financial year: ", - EF4_trendPlot_data()$fyear, - "
", - "Health Board: ", - EF4_trendPlot_data()$hb_name, - "
", - EF4_trendPlot_data()$measure,": ", - EF4_trendPlot_data()$value) - - ## Create the main body of the chart ---- - - # phs_scatterPlot(EF4_trendPlot_data, fyear, value, tooltip_EF4, measure) - - plot_ly(data = EF4_trendPlot_data(), - # Select your variables. - x = ~fyear, y = ~value, color = ~measure, - text = tooltip_EF4, hoverinfo = "text", - colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), # line colours - type = 'scatter', mode = 'lines+markers', - # width = 600, height = 300, - line = list(width = 2), - linetype = ~measure, - linetypes = c("solid", "dash"), - marker = list(size = 8), - name = ~str_wrap(measure, 19)) %>% # legend labels - - # data = EF4_trendPlot_data(), - # # Select your variables. - # x = ~fyear, y = ~value, - # text = tooltip_EF4, hoverinfo = "text", - # color = ~measure, - # colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), # line colours - # type = 'scatter', mode = 'lines+markers', - # # width = 600, height = 300, - # line = list(width = 2), - # linetype = ~measure, - # linetypes = c("solid", "dash"), - # marker = list(size = 8), - # name = ~str_wrap(measure, 19)) %>% # legend labels - - ### 7 - Graph title ---- - layout(title = - paste0( - "", - "Percent (%) of total NHS spend in ", - input$EF4_trendPlot_hbName_output, ",", - "
", - first(as.vector(EF4_trendPlot_data()$fyear)), - " to ", - last(as.vector(EF4_trendPlot_data()$fyear)), - "
", - "
" - ), - - separators = ".", - - yaxis = list( - exponentformat = "none", - separatethousands = TRUE, - range = c(0, max(EF4_trendPlot_data()$value, na.rm = TRUE) - + (max(EF4_trendPlot_data()$value, na.rm = TRUE)*0.1) - ), - # Define Y axis title - title = paste0(c(rep(" ", 20), - "Percent", - rep(" ", 20), - rep("\n ", 3))), - showline = TRUE, - ticks = "outside" - ), - - xaxis = list( - title = paste0(c("
", "Financial year")), - showline = TRUE, - ticks = "outside" - ), - - margin = list(l = 90, r = 60, b = 180, t = 120), - title = list(size = 15), - font = list(size = 13), - # Legend - showlegend = TRUE, - legend = list(x = 1, - y = 1, - bgcolor = 'rgba(255, 255, 255, 0)', - bordercolor = 'rgba(255, 255, 255, 0)') - # legend = list(orientation = "h", # show entries horizontally - # xanchor = "center", # use center of legend as anchor - # x = 0.5, y = -0.9) # put legend in center of x-axis - ) %>% - - ### Remove unnecessary buttons from the modebar ---- - - config(displayModeBar = TRUE, - modeBarButtonsToRemove = bttn_remove, - displaylogo = F, editable = F) - - # } -}) +# Create the EF4 line chart ---- -### Table below graph ---- + ### Render plotly ---- -# output$EF4_1_trend_table <- renderDataTable({ -# datatable(EF4_trendPlot_data(), -# style = 'bootstrap', -# class = 'table-bordered table-condensed', -# rownames = FALSE, -# options = list(pageLength = 16, autoWidth = TRUE, dom = 'tip'), -# colnames = c("Financial year", -# "Area of Residence", -# "Number of Bed Days")) + output$EF4_trendPlot <- renderPlotly({ + + ### Create reactive ggplot graph ---- + + EF4_plot_graph <- reactive ({ + + ggplot(data = EF4_trendPlot_data(), + aes(x = fyear, + y = value, + group = measure, + color = measure, + linetype = measure, + shape = measure, + text = paste0("Financial year: ", # for tooltip in ggplotly - shows values on hover + EF4_trendPlot_data()$fyear, + "
", + "Health Board: ", + EF4_trendPlot_data()$hb_name, + "
", + EF4_trendPlot_data()$measure,": ", + EF4_trendPlot_data()$value)) + ) + + geom_line() + + guides(linetype = "none", + shape = "none", + color = guide_legend(title = "Measure Name", + nrow = 2)) + + scale_color_manual(values = c("#0078D4", "#3393DD"), # colour for lines + labels = ~ stringr::str_wrap(.x, width = 15)) + + scale_linetype_manual(values = c("solid", "dashed")) + + geom_point(size = 2.5) + + scale_shape_manual(values = c("circle", "triangle-up")) + # shape for points + theme_classic()+ + theme(panel.grid.major.x = element_line(), # Shows vertical grid lines + panel.grid.major.y = element_line(), # Shows horizontal grid lines + axis.title.x = element_text(size = 12, + color = "black", + face = "bold"), + axis.title.y = element_text(size = 12, + color = "black", + face = "bold")) + + labs(x = "Financial Year", + y = "Percentage (%)") + + scale_y_continuous(expand = c(0, 0), # y axis will always start from zero + limits = c(0, (max(EF4_trendPlot_data()$value) + + 0.5*max(EF4_trendPlot_data()$value)))) # maximum y axis value should always show + + }) + + + ### Run ggplot graph through plotly ---- + + ggplotly(EF4_plot_graph(), + tooltip = "text") # uses text set up in ggplot aes above. + + }) + + + + ### Table below graph ---- + + # output$EF4_1_trend_table <- renderDataTable({ + # datatable(EF4_trendPlot_data(), + # style = 'bootstrap', + # class = 'table-bordered table-condensed', + # rownames = FALSE, + # options = list(pageLength = 16, autoWidth = TRUE, dom = 'tip'), + # colnames = c("Financial year", + # "Area of Residence", + # "Number of Bed Days")) + # }) + + + +# X OLD CODE ---- +# +# ## plotly bar chart ---- +# output$EF4_trendPlot <- renderPlotly({ +# # +# # # # No data plot +# # # if(sum(EF4_trendPlot_data()$value) == 0 & +# # # !is.na(sum(EF4_trendPlot_data()$value))) +# # # +# # # { +# # # noDataPlot(phs_colours("phs-purple")) +# # # } +# # # +# # # else { +# # +# ### Tooltip creation ---- +# tooltip_EF4 <- paste0("Financial year: ", +# EF4_trendPlot_data()$fyear, +# "
", +# "Health Board: ", +# EF4_trendPlot_data()$hb_name, +# "
", +# EF4_trendPlot_data()$measure,": ", +# EF4_trendPlot_data()$value) +# +# ## Create the main body of the chart ---- +# +# # phs_scatterPlot(EF4_trendPlot_data, fyear, value, tooltip_EF4, measure) +# +# plot_ly(data = EF4_trendPlot_data(), +# # Select your variables. +# x = ~fyear, y = ~value, color = ~measure, +# text = tooltip_EF4, hoverinfo = "text", +# colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), # line colours +# type = 'scatter', mode = 'lines+markers', +# # width = 600, height = 300, +# line = list(width = 2), +# linetype = ~measure, +# linetypes = c("solid", "dash"), +# marker = list(size = 8), +# name = ~str_wrap(measure, 19)) %>% # legend labels +# +# # data = EF4_trendPlot_data(), +# # # Select your variables. +# # x = ~fyear, y = ~value, +# # text = tooltip_EF4, hoverinfo = "text", +# # color = ~measure, +# # colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), # line colours +# # type = 'scatter', mode = 'lines+markers', +# # # width = 600, height = 300, +# # line = list(width = 2), +# # linetype = ~measure, +# # linetypes = c("solid", "dash"), +# # marker = list(size = 8), +# # name = ~str_wrap(measure, 19)) %>% # legend labels +# +# ### 7 - Graph title ---- +# layout(title = +# paste0( +# "", +# "Percent (%) of total NHS spend in ", +# input$EF4_trendPlot_hbName_output, ",", +# "
", +# first(as.vector(EF4_trendPlot_data()$fyear)), +# " to ", +# last(as.vector(EF4_trendPlot_data()$fyear)), +# "
", +# "
" +# ), +# +# separators = ".", +# +# yaxis = list( +# exponentformat = "none", +# separatethousands = TRUE, +# range = c(0, max(EF4_trendPlot_data()$value, na.rm = TRUE) +# + (max(EF4_trendPlot_data()$value, na.rm = TRUE)*0.1) +# ), +# # Define Y axis title +# title = paste0(c(rep(" ", 20), +# "Percent", +# rep(" ", 20), +# rep("\n ", 3))), +# showline = TRUE, +# ticks = "outside" +# ), +# +# xaxis = list( +# title = paste0(c("
", "Financial year")), +# showline = TRUE, +# ticks = "outside" +# ), +# +# margin = list(l = 90, r = 60, b = 180, t = 120), +# title = list(size = 15), +# font = list(size = 13), +# # Legend +# showlegend = TRUE, +# legend = list(x = 1, +# y = 1, +# bgcolor = 'rgba(255, 255, 255, 0)', +# bordercolor = 'rgba(255, 255, 255, 0)') +# # legend = list(orientation = "h", # show entries horizontally +# # xanchor = "center", # use center of legend as anchor +# # x = 0.5, y = -0.9) # put legend in center of x-axis +# ) %>% +# +# ### Remove unnecessary buttons from the modebar ---- +# +# config(displayModeBar = TRUE, +# modeBarButtonsToRemove = bttn_remove, +# displaylogo = F, editable = F) +# +# # } +# # }) - - - +# +# +# ### Table below graph ---- +# +# # output$EF4_1_trend_table <- renderDataTable({ +# # datatable(EF4_trendPlot_data(), +# # style = 'bootstrap', +# # class = 'table-bordered table-condensed', +# # rownames = FALSE, +# # options = list(pageLength = 16, autoWidth = TRUE, dom = 'tip'), +# # colnames = c("Financial year", +# # "Area of Residence", +# # "Number of Bed Days")) +# # }) +# +# +# diff --git a/modules/indicators/EF4_ui.R b/modules/indicators/EF4_ui.R index 4dc0745..b12bf79 100644 --- a/modules/indicators/EF4_ui.R +++ b/modules/indicators/EF4_ui.R @@ -2,6 +2,20 @@ tabItem(tabName = "EF4_tab", fluidPage( # Defining the title h1("EF4 - Total mental health spend as a % of total spend"), + + ## Text Above Graph ---- + fluidRow( + column(12, + box(width = NULL, + p(paste0( + "Below is a graph showing the percentage (%) of your selected ", + "NHS Health Board's total spend that is attributable to total mental ", + "health spend for each financial year. ", + "Use the drop down menus to select which Health Board and ", + "measure(s) you wish to look at.")) + ) + )), # end of fluidRow + ## Drop down menus ---- fluidRow( column(6, box(width = NULL, @@ -12,7 +26,8 @@ tabItem(tabName = "EF4_tab", uiOutput("EF4_trendPlot_measure_output")) ), ), - # ), + + ## Graph output ---- fluidRow( box(width = 12, plotlyOutput("EF4_trendPlot", From 3533edd093112dfa56e24bafe445b7737c53600a Mon Sep 17 00:00:00 2001 From: MahriScot Date: Thu, 26 Sep 2024 15:58:21 +0100 Subject: [PATCH 54/75] EQ1 graphs now ggplot before plotly. Graph titles reworded and positioned as well. --- modules/indicators/E1_server.R | 3 +- modules/indicators/EQ1_server.R | 1072 ++++++++++++++++++------------- modules/indicators/EQ1_ui.R | 63 +- 3 files changed, 684 insertions(+), 454 deletions(-) diff --git a/modules/indicators/E1_server.R b/modules/indicators/E1_server.R index d89a6c1..e8a0d33 100644 --- a/modules/indicators/E1_server.R +++ b/modules/indicators/E1_server.R @@ -28,7 +28,6 @@ output$E1_plot1_areaName_output <- renderUI({ }) ## Selecting appropriate data for graph 1 ---- -### Is this where the error "Argument 1 is not a Vector" is coming from? ---- E1_plot1_Data <- reactive({ E1_data %>% select(fyear, area_type, area_name, dd_bed_days) %>% @@ -63,7 +62,7 @@ output$E1_plot1 <- renderPlotly({ E1_plot1_Data()$area_name, "
", "Total number of bed days: ", - E1_plot1_Data()$dd_bed_days), # for tooltip in ggplotly - shows values on hover + E1_plot1_Data()$dd_bed_days) # for tooltip in ggplotly - shows values on hover ) ) + geom_line() + diff --git a/modules/indicators/EQ1_server.R b/modules/indicators/EQ1_server.R index 1d59b55..8b2bbfd 100644 --- a/modules/indicators/EQ1_server.R +++ b/modules/indicators/EQ1_server.R @@ -1,4 +1,6 @@ -# PLOT 1 (MS added title) ---- +# PLOT 1 ---- + +## Picker for selecting HB or CA ---- output$EQ1_plot1_areaType_output <- renderUI({ shinyWidgets::pickerInput( @@ -8,6 +10,8 @@ output$EQ1_plot1_areaType_output <- renderUI({ selected = "Health board") }) +## Picker for user selecting specific geographies ---- + output$EQ1_plot1_areaName_output <- renderUI({ shinyWidgets::pickerInput( "EQ1_plot1_areaName", @@ -19,10 +23,13 @@ output$EQ1_plot1_areaName_output <- renderUI({ , multiple = TRUE, options = list("max-options" = 4, - `selected-text-format` = "count > 1") + `selected-text-format` = "count > 1"), + selected = "NHS Ayrshire and Arran" ) }) +## Selecting appropriate data for graph 1 ---- + EQ1_plot1_Data <- reactive({ EQ1_data %>% select(Year, area_type, area_name, risk_ratio, SMR04_Pop_Rate, General_Pop_Rate) %>% @@ -31,474 +38,661 @@ EQ1_plot1_Data <- reactive({ }) +# Create the risk ratios line chart ---- -# Create the risk ratios line chart. + ### Render Plotly ---- output$EQ1_plot1 <- renderPlotly({ -# -# # # No data plot -# # if(sum(E1_plot1_Data()$dd_bed_days) == 0 & -# # !is.na(sum(E1_plot1_Data()$dd_bed_days))) -# # -# # { -# # noDataPlot(phs_colours("phs-purple")) -# # } -# # -# # else { -# - ### 3 - Tooltip creation ---- - - tooltip_EQ1 <- paste0("Financial year: ", - EQ1_plot1_Data()$Year, - "
", - "Area of residence: ", - EQ1_plot1_Data()$area_name, - "
", - "Mortality rate: ", - EQ1_plot1_Data()$risk_ratio) - - ### 4 - Create the main body of the chart ---- - - plot_ly(data = EQ1_plot1_Data(), - # Select your variables. - x = ~as.factor(Year), y = ~risk_ratio, color = ~area_name, - colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), - text = tooltip_EQ1, hoverinfo = "text", - type = 'scatter', mode = 'lines+markers', - # width = 600, height = 300, - line = list(width = 3), - linetype = ~area_name, - linetypes = c("solid", "dot"), - # Select symbols for the health boards, and set their size. - symbol = ~area_name, - symbols = c("circle", "triangle-up", "circle", "triangle-up"), - marker = list(size = 12), - name = ~str_wrap(area_name, 19)) %>% # legend labels - - ### 7 - Graph title ---- - - # Make the graph title reactive. - - layout(title = - paste0( - "", - "Mortality rate for persons in contact with MH services", - "
", - " by ", input$EQ1_plot1_areaType, ", ", first(as.vector(EQ1_plot1_Data()$Year)), - " to ", - last(as.vector(EQ1_plot1_Data()$Year)), - "
", - "
" - ), - - separators = ".", - - yaxis = list( - exponentformat = "none", - separatethousands = TRUE, - range = c(0, max(EQ1_plot1_Data()$risk_ratio, na.rm = TRUE) - + (max(EQ1_plot1_Data()$risk_ratio, na.rm = TRUE)*0.1) - ), - title = paste0(c(rep(" ", 20), - input$EQ1_1_input_1, - rep(" ", 20), - rep("\n ", 3))), - showline = TRUE, - ticks = "outside" - ), - - xaxis = list( - title = paste0(c("
", - "Calendar year", - collapse = "")), # Don't think it's needed - showline = TRUE, - ticks = "outside" - ), - - margin = list(l = 90, r = 60, b = 180, t = 120), - title = list(size = 15), - font = list(size = 13), - # Legend - showlegend = TRUE, - legend = list(x = 1, - y = 1, - bgcolor = 'rgba(255, 255, 255, 0)', - bordercolor = 'rgba(255, 255, 255, 0)') - # legend = list(orientation = "h", # show entries horizontally - # xanchor = "center", # use center of legend as anchor - # x = 0.5, y = -0.9) # put legend in center of x-axis - ) %>% - - ### 13 - Remove unnecessary buttons from the modebar ---- - - config(displayModeBar = TRUE, - modeBarButtonsToRemove = bttn_remove, - displaylogo = F, editable = F) - - # } + + ### Create reactive ggplot graph ---- + + EQ1_plot1_graph <- reactive({ + ggplot(data = EQ1_plot1_Data(), + aes(x = Year, + y = risk_ratio, + group = area_name, + color = area_name, + line_type = area_name, + shape = area_name, + text = paste0("Financial year: ", # for tooltip in ggplotly - shows values on hover + EQ1_plot1_Data()$Year, + "
", + "Area of residence: ", + EQ1_plot1_Data()$area_name, + "
", + "Mortality rate: ", + EQ1_plot1_Data()$risk_ratio))) + + geom_line() + + # guides(linetype = "none", # working on this below in "labs" + # shape = "none", + # # shape = FALSE, + # color = guide_legend(title = "Area name:", + # nrow = 4)) + + scale_color_manual(values = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), + labels = ~ stringr::str_wrap(.x, width = 15)) + + scale_linetype_manual(values = c("solid", "dashed", "solid", "dashed")) + + geom_point(size = 2.5) + + scale_shape_manual(values = c("circle", "circle", "triangle-up", "triangle-up")) + + theme_classic() + # de-clutters graph background + theme(panel.grid.major.x = element_line(), # Shows vertical grid lines + panel.grid.major.y = element_line(), # Shows horizontal grid lines + axis.title.x = element_text(size = 12, + color = "black", + face = "bold"), + axis.title.y = element_text(size = 12, + color = "black", + face = "bold"), + legend.position = "right", # added to test + legend.text = element_text(size = 8, + colour = "black"), + legend.title = element_text(size = 9, + colour = "black", + face = "bold")) + + labs(x = "Year", + y = "Mortality Rate", + color = "Area:", + shape = NULL) + + scale_y_continuous(expand = c(0, 0), # Ensures y axis starts from zero + limits = c(0, (max(EQ1_plot1_Data()$risk_ratio) + 0.5*max(EQ1_plot1_Data()$risk_ratio)))) + }) + + + ### Run graph 1 through plotly ---- + + ggplotly(EQ1_plot1_graph(), + tooltip = "text")#, # uses text set up in ggplot aes above. + # ### Remove unnecessary buttons from the modebar ---- not working just now + # config(displayModeBar = TRUE, # Remove unnecessary buttons from the modebar + # modeBarButtonsToRemove = bttn_remove, + # displaylogo = F, editable = F)) + +}) + + + +# EQ1 PLOT 2 ---- +## Picker for user selecting HB or CA ---- + +output$EQ1_plot4_areaType_output <- renderUI({ + shinyWidgets::pickerInput( + "EQ1_plot4_areaType", + label = "Select type of geography:", + choices = unique_area_types, + selected = "Health board") +}) + +## Picker for user selecting specific geographies ---- +output$EQ1_plot4_areaName_output <- renderUI({ + shinyWidgets::pickerInput( + "EQ1_plot4_areaName", + label = "Select area:", + choices = sort(unique(as.character( + EQ1_reformatted_data$area_name + [EQ1_reformatted_data$area_type %in% input$EQ1_plot4_areaType] + ))), + multiple = TRUE, + options = list("max-options" = 1, + `selected-text-format` = "count > 1"), + selected = "NHS Ayrshire and Arran") +}) + + +## Selecting appropriate data for graph 2 ---- + +EQ1_plot4_Data <- reactive({ + EQ1_reformatted_data %>% + select(Rate_Type, Year, area_type, area_name, Rate) %>% + filter(area_type %in% input$EQ1_plot4_areaType + & area_name %in% input$EQ1_plot4_areaName) }) +# Create the combined general population and MH rates bar chart ---- + + ### Render plotly ---- + +output$EQ1_plot4 <- renderPlotly({ + + ### Create reactive ggplot bar graph ---- + + EQ1_plot4_graph <- reactive({ + ggplot(data = EQ1_plot4_Data(), + aes(x = Year, + y = Rate, + fill = Rate_Type, # colours defined below + text = paste0("Financial year: ", + EQ1_plot4_Data()$Year, + "
", + "Area of residence: ", + EQ1_plot4_Data()$area_name, + "
", + "Rate Type: ", + EQ1_plot4_Data()$Rate_Type, + "
", + "Rate: ", + EQ1_plot4_Data()$Rate) + )) + + geom_bar(stat = "identity", position = "dodge") + # creates bar graph with bars separated from each other + scale_fill_manual(values = c("#0078D4", "#B3D7F2")) + + theme_classic() + + theme(#legend.position = "bottom", # WHY ISN'T THIS WORKING? + panel.grid.major.x = element_line(), # Shows vertical grid lines + panel.grid.major.y = element_line(), # Shows horizontal grid lines + axis.title.x = element_text(size = 12, + color = "black", + face = "bold"), + axis.title.y = element_text(size = 12, + color = "black", + face = "bold")) + + labs(x = "Year", + y = "Mortality Rate", + fill = "Population Group:") + + scale_y_continuous(expand = c(0, 0), # Ensures y axis starts from zero + limits = c(0, (max(EQ1_plot4_Data()$Rate) + 0.5*max(EQ1_plot4_Data()$Rate)))) + + }) + + +### Run graph 2 through plotly ---- + + ggplotly(EQ1_plot4_graph(), + tooltip = "text")#, # uses text set up in ggplot aes above. + # ### Remove unnecessary buttons from the modebar ---- not working but will make work + # config(displayModeBar = TRUE, + # modeBarButtonsToRemove = bttn_remove, + # displaylogo = F, editable = F)) + +}) + + + +# Table below graph creation ---- + +# output$E1_1_trend_table <- renderDataTable({ +# datatable(E1_plot1_Data(), +# style = 'bootstrap', +# class = 'table-bordered table-condensed', +# rownames = FALSE, +# options = list(pageLength = 16, autoWidth = TRUE, dom = 'tip'), +# colnames = c("Financial year", +# "Area of Residence", +# "Number of Bed Days")) +# }) + + + + + + +# OLD CODE (keeping in case needed for reference) ---- +# +# # +# # +# # # +# # # # # No data plot +# # # # if(sum(E1_plot1_Data()$dd_bed_days) == 0 & +# # # # !is.na(sum(E1_plot1_Data()$dd_bed_days))) +# # # # +# # # # { +# # # # noDataPlot(phs_colours("phs-purple")) +# # # # } +# # # # +# # # # else { +# # # +# # ### 3 - Tooltip creation ---- +# # +# # tooltip_EQ1 <- paste0("Financial year: ", +# # EQ1_plot1_Data()$Year, +# # "
", +# # "Area of residence: ", +# # EQ1_plot1_Data()$area_name, +# # "
", +# # "Mortality rate: ", +# # EQ1_plot1_Data()$risk_ratio) +# # +# # ### 4 - Create the main body of the chart ---- +# # +# # plot_ly(data = EQ1_plot1_Data(), +# # # Select your variables. +# # x = ~as.factor(Year), y = ~risk_ratio, color = ~area_name, +# # colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), +# # text = tooltip_EQ1, hoverinfo = "text", +# # type = 'scatter', mode = 'lines+markers', +# # # width = 600, height = 300, +# # line = list(width = 3), +# # linetype = ~area_name, +# # linetypes = c("solid", "dot"), +# # # Select symbols for the health boards, and set their size. +# # symbol = ~area_name, +# # symbols = c("circle", "triangle-up", "circle", "triangle-up"), +# # marker = list(size = 12), +# # name = ~str_wrap(area_name, 19)) %>% # legend labels +# # +# # ### 7 - Graph title ---- +# # +# # # Make the graph title reactive. +# # +# # layout(title = +# # paste0( +# # "", +# # "Mortality rate for persons in contact with MH services", +# # "
", +# # " by ", input$EQ1_plot1_areaType, ", ", first(as.vector(EQ1_plot1_Data()$Year)), +# # " to ", +# # last(as.vector(EQ1_plot1_Data()$Year)), +# # "
", +# # "
" +# # ), +# # +# # separators = ".", +# # +# # yaxis = list( +# # exponentformat = "none", +# # separatethousands = TRUE, +# # range = c(0, max(EQ1_plot1_Data()$risk_ratio, na.rm = TRUE) +# # + (max(EQ1_plot1_Data()$risk_ratio, na.rm = TRUE)*0.1) +# # ), +# # title = paste0(c(rep(" ", 20), +# # input$EQ1_1_input_1, +# # rep(" ", 20), +# # rep("\n ", 3))), +# # showline = TRUE, +# # ticks = "outside" +# # ), +# # +# # xaxis = list( +# # title = paste0(c("
", +# # "Calendar year", +# # collapse = "")), # Don't think it's needed +# # showline = TRUE, +# # ticks = "outside" +# # ), +# # +# # margin = list(l = 90, r = 60, b = 180, t = 120), +# # title = list(size = 15), +# # font = list(size = 13), +# # # Legend +# # showlegend = TRUE, +# # legend = list(x = 1, +# # y = 1, +# # bgcolor = 'rgba(255, 255, 255, 0)', +# # bordercolor = 'rgba(255, 255, 255, 0)') +# # # legend = list(orientation = "h", # show entries horizontally +# # # xanchor = "center", # use center of legend as anchor +# # # x = 0.5, y = -0.9) # put legend in center of x-axis +# # ) %>% +# # +# # ### 13 - Remove unnecessary buttons from the modebar ---- +# # +# # config(displayModeBar = TRUE, +# # modeBarButtonsToRemove = bttn_remove, +# # displaylogo = F, editable = F) +# # +# # # } +# # +# # }) # # -# ####### Create the SMR04 rates bar chart. +# # +# # +# # ####### Create the SMR04 rates bar chart. +# # +# # output$EQ1_plot2 <- renderPlotly({ +# # # +# # # # # No data plot +# # # # if(sum(E1_plot1_Data()$dd_bed_days) == 0 & +# # # # !is.na(sum(E1_plot1_Data()$dd_bed_days))) +# # # # +# # # # { +# # # # noDataPlot(phs_colours("phs-purple")) +# # # # } +# # # # +# # # # else { +# # # +# # ### 3 - Tooltip creation ---- +# # +# # tooltip_EQ1_2 <- paste0("Financial year: ", +# # EQ1_plot1_Data()$Year, +# # "
", +# # "Area of residence: ", +# # EQ1_plot1_Data()$area_name, +# # "
", +# # "Mortality rate: ", +# # EQ1_plot1_Data()$SMR04_Pop_Rate) +# # +# # ### 4 - Create the main body of the chart ---- +# # +# # plot_ly(data = EQ1_plot1_Data(), +# # # Select your variables. +# # x = ~Year, y = ~SMR04_Pop_Rate, type = 'bar', color = ~area_name, +# # #add_trace(p = data, y = ~General_Pop_Rate), +# # colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), +# # text = tooltip_EQ1_2, hoverinfo = "text", +# # marker = list(size = 12), +# # name = ~str_wrap(area_name, 19)) %>% # legend labels +# # +# # ### 7 - Graph title ---- +# # +# # # Make the graph title reactive. +# # +# # layout(title = +# # paste0( +# # "", +# # "Mortality rate for persons in contact with MH services", +# # "
", +# # " by ", input$EQ1_plot1_areaType, ", ", first(as.vector(EQ1_plot1_Data()$Year)), +# # " to ", +# # last(as.vector(EQ1_plot1_Data()$Year)), +# # "
", +# # "
" +# # ), +# # +# # separators = ".", +# # +# # yaxis = list( +# # exponentformat = "none", +# # separatethousands = TRUE, +# # range = c(0, max(EQ1_plot1_Data()$SMR04_Pop_Rate, na.rm = TRUE) +# # + (max(EQ1_plot1_Data()$SMR04_Pop_Rate, na.rm = TRUE)*0.1) +# # ), +# # title = paste0(c(rep(" ", 20), +# # input$EQ1_1_input_1, +# # rep(" ", 20), +# # rep("\n ", 3))), +# # showline = TRUE, +# # ticks = "outside" +# # ), +# # +# # xaxis = list( +# # title = paste0(c("
", +# # "Area name", +# # collapse = "")), # Don't think it's needed +# # showline = TRUE, +# # ticks = "outside" +# # ), +# # +# # margin = list(l = 90, r = 60, b = 180, t = 120), +# # title = list(size = 15), +# # font = list(size = 13), +# # # Legend +# # showlegend = TRUE, +# # legend = list(x = 1, +# # y = 1, +# # bgcolor = 'rgba(255, 255, 255, 0)', +# # bordercolor = 'rgba(255, 255, 255, 0)') +# # # legend = list(orientation = "h", # show entries horizontally +# # # xanchor = "center", # use center of legend as anchor +# # # x = 0.5, y = -0.9) # put legend in center of x-axis +# # ) %>% +# # +# # ### 13 - Remove unnecessary buttons from the modebar ---- +# # +# # config(displayModeBar = TRUE, +# # modeBarButtonsToRemove = bttn_remove, +# # displaylogo = F, editable = F) +# # +# # # } +# # +# # }) +# # +# # +# # +# # +# # ####### Create the general population rates bar chart. +# # +# # output$EQ1_plot3 <- renderPlotly({ +# # # +# # # # # No data plot +# # # # if(sum(E1_plot1_Data()$dd_bed_days) == 0 & +# # # # !is.na(sum(E1_plot1_Data()$dd_bed_days))) +# # # # +# # # # { +# # # # noDataPlot(phs_colours("phs-purple")) +# # # # } +# # # # +# # # # else { +# # # +# # ### 3 - Tooltip creation ---- +# # +# # tooltip_EQ1_3 <- paste0("Financial year: ", +# # EQ1_plot1_Data()$Year, +# # "
", +# # "Area of residence: ", +# # EQ1_plot1_Data()$area_name, +# # "
", +# # "Mortality rate: ", +# # EQ1_plot1_Data()$General_Pop_Rate) +# # +# # ### 4 - Create the main body of the chart ---- +# # +# # plot_ly(data = EQ1_plot1_Data(), +# # # Select your variables. +# # x = ~Year, y = ~General_Pop_Rate, type = 'bar', color = ~area_name, +# # #add_trace(p = data, y = ~General_Pop_Rate), +# # colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), +# # text = tooltip_EQ1_3, hoverinfo = "text", +# # marker = list(size = 12), +# # name = ~str_wrap(area_name, 19)) %>% # legend labels +# # +# # ### 7 - Graph title ---- +# # +# # # Make the graph title reactive. +# # +# # layout(title = +# # paste0( +# # "", +# # "Mortality rate for the general population", +# # "
", +# # " by ", input$EQ1_plot1_areaType, ", ", first(as.vector(EQ1_plot1_Data()$Year)), +# # " to ", +# # last(as.vector(EQ1_plot1_Data()$Year)), +# # "
", +# # "
" +# # ), +# # +# # separators = ".", +# # +# # yaxis = list( +# # exponentformat = "none", +# # separatethousands = TRUE, +# # range = c(0, max(EQ1_plot1_Data()$General_Pop_Rate, na.rm = TRUE) +# # + (max(EQ1_plot1_Data()$General_Pop_Rate, na.rm = TRUE)*0.1) +# # ), +# # title = paste0(c(rep(" ", 20), +# # input$EQ1_1_input_1, +# # rep(" ", 20), +# # rep("\n ", 3))), +# # showline = TRUE, +# # ticks = "outside" +# # ), +# # +# # xaxis = list( +# # title = paste0(c("
", +# # "Area name", +# # collapse = "")), # Don't think it's needed +# # showline = TRUE, +# # ticks = "outside" +# # ), +# # +# # margin = list(l = 90, r = 60, b = 180, t = 120), +# # title = list(size = 15), +# # font = list(size = 13), +# # # Legend +# # showlegend = TRUE, +# # legend = list(x = 1, +# # y = 1, +# # bgcolor = 'rgba(255, 255, 255, 0)', +# # bordercolor = 'rgba(255, 255, 255, 0)') +# # # legend = list(orientation = "h", # show entries horizontally +# # # xanchor = "center", # use center of legend as anchor +# # # x = 0.5, y = -0.9) # put legend in center of x-axis +# # ) %>% +# # +# # ### 13 - Remove unnecessary buttons from the modebar ---- +# # +# # config(displayModeBar = TRUE, +# # modeBarButtonsToRemove = bttn_remove, +# # displaylogo = F, editable = F) +# # +# # # } +# # +# # }) +# # +# # # -# output$EQ1_plot2 <- renderPlotly({ -# # -# # # # No data plot -# # # if(sum(E1_plot1_Data()$dd_bed_days) == 0 & -# # # !is.na(sum(E1_plot1_Data()$dd_bed_days))) -# # # -# # # { -# # # noDataPlot(phs_colours("phs-purple")) -# # # } -# # # -# # # else { -# # -# ### 3 - Tooltip creation ---- # -# tooltip_EQ1_2 <- paste0("Financial year: ", -# EQ1_plot1_Data()$Year, -# "
", -# "Area of residence: ", -# EQ1_plot1_Data()$area_name, -# "
", -# "Mortality rate: ", -# EQ1_plot1_Data()$SMR04_Pop_Rate) # -# ### 4 - Create the main body of the chart ---- # -# plot_ly(data = EQ1_plot1_Data(), -# # Select your variables. -# x = ~Year, y = ~SMR04_Pop_Rate, type = 'bar', color = ~area_name, -# #add_trace(p = data, y = ~General_Pop_Rate), -# colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), -# text = tooltip_EQ1_2, hoverinfo = "text", -# marker = list(size = 12), -# name = ~str_wrap(area_name, 19)) %>% # legend labels +# output$EQ1_plot4_areaType_output <- renderUI({ +# shinyWidgets::pickerInput( +# "EQ1_plot4_areaType", +# label = "Select type of geography:", +# choices = unique_area_types, +# selected = "Health board") +# }) # -# ### 7 - Graph title ---- +# output$EQ1_plot4_areaName_output <- renderUI({ +# shinyWidgets::pickerInput( +# "EQ1_plot4_areaName", +# label = "Select area:", +# choices = sort(unique(as.character( +# EQ1_reformatted_data$area_name +# [EQ1_reformatted_data$area_type %in% input$EQ1_plot4_areaType] +# ))) +# , +# multiple = TRUE, +# options = list("max-options" = 1, +# `selected-text-format` = "count > 1") +# ) +# }) # -# # Make the graph title reactive. # -# layout(title = -# paste0( -# "", -# "Mortality rate for persons in contact with MH services", -# "
", -# " by ", input$EQ1_plot1_areaType, ", ", first(as.vector(EQ1_plot1_Data()$Year)), -# " to ", -# last(as.vector(EQ1_plot1_Data()$Year)), -# "
", -# "
" -# ), +# EQ1_plot4_Data <- reactive({ +# EQ1_reformatted_data %>% +# select(Rate_Type, Year, area_type, area_name, Rate) %>% +# filter(area_type %in% input$EQ1_plot4_areaType +# & area_name %in% input$EQ1_plot4_areaName) +# }) # -# separators = ".", # -# yaxis = list( -# exponentformat = "none", -# separatethousands = TRUE, -# range = c(0, max(EQ1_plot1_Data()$SMR04_Pop_Rate, na.rm = TRUE) -# + (max(EQ1_plot1_Data()$SMR04_Pop_Rate, na.rm = TRUE)*0.1) -# ), -# title = paste0(c(rep(" ", 20), -# input$EQ1_1_input_1, -# rep(" ", 20), -# rep("\n ", 3))), -# showline = TRUE, -# ticks = "outside" -# ), +# ####### Create the combined general population and MH rates bar chart. +# # +# output$EQ1_plot4 <- renderPlotly({ +# # +# # # # No data plot +# # # if(sum(E1_plot1_Data()$dd_bed_days) == 0 & +# # # !is.na(sum(E1_plot1_Data()$dd_bed_days))) +# # # +# # # { +# # # noDataPlot(phs_colours("phs-purple")) +# # # } +# # # +# # # else { +# # +# ### 3 - Tooltip creation ---- # -# xaxis = list( -# title = paste0(c("
", -# "Area name", -# collapse = "")), # Don't think it's needed -# showline = TRUE, -# ticks = "outside" -# ), +# tooltip_EQ1_4 <- paste0("Financial year: ", +# EQ1_plot4_Data()$Year, +# "
", +# "Area of residence: ", +# EQ1_plot4_Data()$area_name, +# "
", +# "Rate Type: ", +# EQ1_plot4_Data()$Rate_Type, +# "
", +# "Rate: ", +# EQ1_plot4_Data()$Rate) # -# margin = list(l = 90, r = 60, b = 180, t = 120), -# title = list(size = 15), -# font = list(size = 13), -# # Legend -# showlegend = TRUE, -# legend = list(x = 1, -# y = 1, -# bgcolor = 'rgba(255, 255, 255, 0)', -# bordercolor = 'rgba(255, 255, 255, 0)') -# # legend = list(orientation = "h", # show entries horizontally -# # xanchor = "center", # use center of legend as anchor -# # x = 0.5, y = -0.9) # put legend in center of x-axis -# ) %>% +# ### 4 - Create the main body of the chart ---- # -# ### 13 - Remove unnecessary buttons from the modebar ---- +# plot_ly(data = EQ1_plot4_Data(), +# # Select your variables. +# x = ~Year, y = ~Rate, type = 'bar', color = ~Rate_Type, +# colors = c("#0078D4", "#B3D7F2"), +# textposition = "none", +# text = tooltip_EQ1_4, hoverinfo = "text", +# marker = list(size = 12), +# name = ~str_wrap(Rate_Type, 19)) %>% # legend labels # -# config(displayModeBar = TRUE, -# modeBarButtonsToRemove = bttn_remove, -# displaylogo = F, editable = F) +# ### 7 - Graph title ---- # -# # } +# # Make the graph title reactive. # -# }) +# layout(title = +# paste0( +# "", +# "Mortality rates for the MH and general population", +# "
", +# " for ", input$EQ1_plot4_areaName, ", ", first(as.vector(EQ1_plot4_Data()$Year)), +# " to ", +# last(as.vector(EQ1_plot4_Data()$Year)), +# "
", +# "
" +# ), # +# separators = ".", # +# yaxis = list( +# exponentformat = "none", +# separatethousands = TRUE, +# range = c(0, max(EQ1_plot4_Data()$Rate, na.rm = TRUE) +# + (max(EQ1_plot4_Data()$Rate, na.rm = TRUE)*0.1) +# ), +# title = paste0(c(rep(" ", 20), +# input$EQ1_1_input_1, +# rep(" ", 20), +# rep("\n ", 3))), +# showline = TRUE, +# ticks = "outside" +# ), # +# xaxis = list( +# title = paste0(c("
", +# "Area name", +# collapse = "")), # Don't think it's needed +# showline = TRUE, +# ticks = "outside" +# ), # -# ####### Create the general population rates bar chart. +# margin = list(l = 90, r = 60, b = 180, t = 120), +# title = list(size = 15), +# font = list(size = 13), +# # Legend +# showlegend = TRUE, +# legend = list(x = 1, +# y = 1, +# bgcolor = 'rgba(255, 255, 255, 0)', +# bordercolor = 'rgba(255, 255, 255, 0)') +# # legend = list(orientation = "h", # show entries horizontally +# # xanchor = "center", # use center of legend as anchor +# # x = 0.5, y = -0.9) # put legend in center of x-axis +# ) %>% # -# output$EQ1_plot3 <- renderPlotly({ -# # -# # # # No data plot -# # # if(sum(E1_plot1_Data()$dd_bed_days) == 0 & -# # # !is.na(sum(E1_plot1_Data()$dd_bed_days))) -# # # -# # # { -# # # noDataPlot(phs_colours("phs-purple")) -# # # } -# # # -# # # else { -# # -# ### 3 - Tooltip creation ---- -# -# tooltip_EQ1_3 <- paste0("Financial year: ", -# EQ1_plot1_Data()$Year, -# "
", -# "Area of residence: ", -# EQ1_plot1_Data()$area_name, -# "
", -# "Mortality rate: ", -# EQ1_plot1_Data()$General_Pop_Rate) -# -# ### 4 - Create the main body of the chart ---- -# -# plot_ly(data = EQ1_plot1_Data(), -# # Select your variables. -# x = ~Year, y = ~General_Pop_Rate, type = 'bar', color = ~area_name, -# #add_trace(p = data, y = ~General_Pop_Rate), -# colors = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), -# text = tooltip_EQ1_3, hoverinfo = "text", -# marker = list(size = 12), -# name = ~str_wrap(area_name, 19)) %>% # legend labels -# -# ### 7 - Graph title ---- -# -# # Make the graph title reactive. -# -# layout(title = -# paste0( -# "", -# "Mortality rate for the general population", -# "
", -# " by ", input$EQ1_plot1_areaType, ", ", first(as.vector(EQ1_plot1_Data()$Year)), -# " to ", -# last(as.vector(EQ1_plot1_Data()$Year)), -# "
", -# "
" -# ), -# -# separators = ".", -# -# yaxis = list( -# exponentformat = "none", -# separatethousands = TRUE, -# range = c(0, max(EQ1_plot1_Data()$General_Pop_Rate, na.rm = TRUE) -# + (max(EQ1_plot1_Data()$General_Pop_Rate, na.rm = TRUE)*0.1) -# ), -# title = paste0(c(rep(" ", 20), -# input$EQ1_1_input_1, -# rep(" ", 20), -# rep("\n ", 3))), -# showline = TRUE, -# ticks = "outside" -# ), -# -# xaxis = list( -# title = paste0(c("
", -# "Area name", -# collapse = "")), # Don't think it's needed -# showline = TRUE, -# ticks = "outside" -# ), -# -# margin = list(l = 90, r = 60, b = 180, t = 120), -# title = list(size = 15), -# font = list(size = 13), -# # Legend -# showlegend = TRUE, -# legend = list(x = 1, -# y = 1, -# bgcolor = 'rgba(255, 255, 255, 0)', -# bordercolor = 'rgba(255, 255, 255, 0)') -# # legend = list(orientation = "h", # show entries horizontally -# # xanchor = "center", # use center of legend as anchor -# # x = 0.5, y = -0.9) # put legend in center of x-axis -# ) %>% -# -# ### 13 - Remove unnecessary buttons from the modebar ---- -# -# config(displayModeBar = TRUE, -# modeBarButtonsToRemove = bttn_remove, -# displaylogo = F, editable = F) -# -# # } -# -# }) +# ### 13 - Remove unnecessary buttons from the modebar ---- # +# config(displayModeBar = TRUE, +# modeBarButtonsToRemove = bttn_remove, +# displaylogo = F, editable = F) +# +# # } +# +# }) +# +# +# ### 15 - Table below graph creation ---- +# +# # output$E1_1_trend_table <- renderDataTable({ +# # datatable(E1_plot1_Data(), +# # style = 'bootstrap', +# # class = 'table-bordered table-condensed', +# # rownames = FALSE, +# # options = list(pageLength = 16, autoWidth = TRUE, dom = 'tip'), +# # colnames = c("Financial year", +# # "Area of Residence", +# # "Number of Bed Days")) +# # }) # - - - - -output$EQ1_plot4_areaType_output <- renderUI({ - shinyWidgets::pickerInput( - "EQ1_plot4_areaType", - label = "Select type of geography:", - choices = unique_area_types, - selected = "Health board") -}) - -output$EQ1_plot4_areaName_output <- renderUI({ - shinyWidgets::pickerInput( - "EQ1_plot4_areaName", - label = "Select area:", - choices = sort(unique(as.character( - EQ1_reformatted_data$area_name - [EQ1_reformatted_data$area_type %in% input$EQ1_plot4_areaType] - ))) - , - multiple = TRUE, - options = list("max-options" = 1, - `selected-text-format` = "count > 1") - ) -}) - - -EQ1_plot4_Data <- reactive({ - EQ1_reformatted_data %>% - select(Rate_Type, Year, area_type, area_name, Rate) %>% - filter(area_type %in% input$EQ1_plot4_areaType - & area_name %in% input$EQ1_plot4_areaName) -}) - - -####### Create the combined general population and MH rates bar chart. -# - output$EQ1_plot4 <- renderPlotly({ - # - # # # No data plot - # # if(sum(E1_plot1_Data()$dd_bed_days) == 0 & - # # !is.na(sum(E1_plot1_Data()$dd_bed_days))) - # # - # # { - # # noDataPlot(phs_colours("phs-purple")) - # # } - # # - # # else { - # - ### 3 - Tooltip creation ---- - - tooltip_EQ1_4 <- paste0("Financial year: ", - EQ1_plot4_Data()$Year, - "
", - "Area of residence: ", - EQ1_plot4_Data()$area_name, - "
", - "Rate Type: ", - EQ1_plot4_Data()$Rate_Type, - "
", - "Rate: ", - EQ1_plot4_Data()$Rate) - - ### 4 - Create the main body of the chart ---- - - plot_ly(data = EQ1_plot4_Data(), - # Select your variables. - x = ~Year, y = ~Rate, type = 'bar', color = ~Rate_Type, - colors = c("#0078D4", "#B3D7F2"), - textposition = "none", - text = tooltip_EQ1_4, hoverinfo = "text", - marker = list(size = 12), - name = ~str_wrap(Rate_Type, 19)) %>% # legend labels - - ### 7 - Graph title ---- - - # Make the graph title reactive. - - layout(title = - paste0( - "", - "Mortality rates for the MH and general population", - "
", - " for ", input$EQ1_plot4_areaName, ", ", first(as.vector(EQ1_plot4_Data()$Year)), - " to ", - last(as.vector(EQ1_plot4_Data()$Year)), - "
", - "
" - ), - - separators = ".", - - yaxis = list( - exponentformat = "none", - separatethousands = TRUE, - range = c(0, max(EQ1_plot4_Data()$Rate, na.rm = TRUE) - + (max(EQ1_plot4_Data()$Rate, na.rm = TRUE)*0.1) - ), - title = paste0(c(rep(" ", 20), - input$EQ1_1_input_1, - rep(" ", 20), - rep("\n ", 3))), - showline = TRUE, - ticks = "outside" - ), - - xaxis = list( - title = paste0(c("
", - "Area name", - collapse = "")), # Don't think it's needed - showline = TRUE, - ticks = "outside" - ), - - margin = list(l = 90, r = 60, b = 180, t = 120), - title = list(size = 15), - font = list(size = 13), - # Legend - showlegend = TRUE, - legend = list(x = 1, - y = 1, - bgcolor = 'rgba(255, 255, 255, 0)', - bordercolor = 'rgba(255, 255, 255, 0)') - # legend = list(orientation = "h", # show entries horizontally - # xanchor = "center", # use center of legend as anchor - # x = 0.5, y = -0.9) # put legend in center of x-axis - ) %>% - - ### 13 - Remove unnecessary buttons from the modebar ---- - - config(displayModeBar = TRUE, - modeBarButtonsToRemove = bttn_remove, - displaylogo = F, editable = F) - - # } - - }) - - -### 15 - Table below graph creation ---- - -# output$E1_1_trend_table <- renderDataTable({ -# datatable(E1_plot1_Data(), -# style = 'bootstrap', -# class = 'table-bordered table-condensed', -# rownames = FALSE, -# options = list(pageLength = 16, autoWidth = TRUE, dom = 'tip'), -# colnames = c("Financial year", -# "Area of Residence", -# "Number of Bed Days")) -# }) - diff --git a/modules/indicators/EQ1_ui.R b/modules/indicators/EQ1_ui.R index 6947f7b..09431df 100644 --- a/modules/indicators/EQ1_ui.R +++ b/modules/indicators/EQ1_ui.R @@ -1,7 +1,28 @@ +# Beginning of EQ1 tab ---- + tabItem(tabName = "EQ1_tab", fluidPage( h1("EQ1 - Premature mortality rate = Standardised mortality rate ", "for persons in contact with mental health services"), + + hr(), # page break + + + # First Graph ---- + # Text above graph + fluidRow( + column(12, + box(width = NULL, + p("Below is a graph showing the changes over time of the ", + "mortality rates for persons in contact with mental health ", + "services. ", + br(), + "This is broken down by either council area or health board of ", + "residence. Please use the drop down menus to select which ", + "areas you wish to look at."))) + ), + + # Geography Drop Down Menus fluidRow( column(6, box(width = NULL, @@ -12,34 +33,50 @@ tabItem(tabName = "EQ1_tab", uiOutput("EQ1_plot1_areaName_output")) ), ), - fluidRow( - column(12, - box(width = NULL, - p("Below is a graph showing the changes over time."))) - ), + # Graph 1 output fluidRow( box(width = 12, phs_spinner("EQ1_plot1")) ), - fluidRow( + + + hr(), # page break + + + # Second graph ---- + # Text above graph + fluidRow( + column(12, + box(width = NULL, + p("Below is a graph showing the changes over time of the ", + "mortality rates for the general population and the mental ", + "health population for your chosen area.", + br(), + "This is broken down by either council area or health board of ", + "residence. Please use the drop down menus to select which ", + "areas you wish to look at."))) + ), + + # Geography Drop Down Menus + fluidRow( column(6, box(width = NULL, - uiOutput("EQ1_plot4_areaType_output")) - ), + uiOutput("EQ1_plot4_areaType_output"))), column(6, box(width = NULL, - uiOutput("EQ1_plot4_areaName_output")) + uiOutput("EQ1_plot4_areaName_output"))), ), - ), - br(), - fluidRow( + + # Graph 2 output + fluidRow( box(width = 12, phs_spinner("EQ1_plot4")) - ), + ), br(), + # Navigation Buttons ---- go_2_top_bttn, br(), From 0acc90374ef648528ef9229763e599e800ad6b28 Mon Sep 17 00:00:00 2001 From: MahriScot Date: Thu, 26 Sep 2024 16:02:08 +0100 Subject: [PATCH 55/75] E1 graph 1 now shows data when page is loaded --- modules/indicators/E1_server.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/indicators/E1_server.R b/modules/indicators/E1_server.R index e8a0d33..d0507f4 100644 --- a/modules/indicators/E1_server.R +++ b/modules/indicators/E1_server.R @@ -20,10 +20,10 @@ output$E1_plot1_areaName_output <- renderUI({ E1_data$area_name [E1_data$area_type %in% input$E1_plot1_areaType] ))), - selected = "NHS Ayrshire & Arran", multiple = TRUE, options = list("max-options" = 4, - `selected-text-format` = "count > 1") + `selected-text-format` = "count > 1"), + selected = "NHS Ayrshire and Arran" ) }) From 78bac16507e665201455b00dec2a5652f4a0313b Mon Sep 17 00:00:00 2001 From: MahriScot Date: Fri, 27 Sep 2024 12:04:09 +0100 Subject: [PATCH 56/75] EQ1 - first graph now showing legend, also rounded all values --- data_preparation.R | 15 ++--------- modules/indicators/EQ1_server.R | 47 ++++++++++++++++----------------- modules/indicators/EQ1_ui.R | 2 +- 3 files changed, 26 insertions(+), 38 deletions(-) diff --git a/data_preparation.R b/data_preparation.R index 0e8321b..a878adb 100644 --- a/data_preparation.R +++ b/data_preparation.R @@ -22,25 +22,14 @@ unique_area_types <- EQ1_data %>% distinct(area_type) %>% pull(area_type) # For EQ1 plot 2: -EQ1_reformatted_data <- read.csv("data/EQ1_Reformatted.csv") +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 ---- -# Import data and rename variables - -# EF4_data <- read.csv("data/EF4_Relevant variables.csv") %>% -# rename(fyear = financial_year, -# "Total Net NHS Expenditure (£ millions)" = total_net_nhs_expenditure, -# "Total Mental Health Expenditure (£ millions)" = total_mental_health_expenditure, -# "Mental Health Expenditure (%)" = mental_health_expenditure_as_a_percent_of_total_nhs_expenditure, -# "CAMHS Expenditure (%)" = camhs_as_percent_of_total_nhs_expenditure) %>% -# tidyr::pivot_longer(cols = -(fyear:hb), -# names_to = 'measure', -# values_to = 'value') - EF4_data <- read.csv("data/EF4.csv") %>% select(fyear, hb_name, measure, value) diff --git a/modules/indicators/EQ1_server.R b/modules/indicators/EQ1_server.R index 8b2bbfd..82cbdb7 100644 --- a/modules/indicators/EQ1_server.R +++ b/modules/indicators/EQ1_server.R @@ -33,6 +33,7 @@ output$EQ1_plot1_areaName_output <- renderUI({ EQ1_plot1_Data <- reactive({ EQ1_data %>% select(Year, area_type, area_name, risk_ratio, SMR04_Pop_Rate, General_Pop_Rate) %>% + mutate(risk_ratio = round(risk_ratio, 2)) %>% # because values are e.g., "5.239755" filter(area_type %in% input$EQ1_plot1_areaType & area_name %in% input$EQ1_plot1_areaName) }) @@ -44,17 +45,14 @@ EQ1_plot1_Data <- reactive({ output$EQ1_plot1 <- renderPlotly({ - ### Create reactive ggplot graph ---- + ### Create reactive ggplot graph ---- + #testing to add legend!! EQ1_plot1_graph <- reactive({ ggplot(data = EQ1_plot1_Data(), aes(x = Year, - y = risk_ratio, - group = area_name, - color = area_name, - line_type = area_name, - shape = area_name, - text = paste0("Financial year: ", # for tooltip in ggplotly - shows values on hover + y = risk_ratio, + text = paste0("Financial year: ", # for tooltip in ggplotly - shows values on hover EQ1_plot1_Data()$Year, "
", "Area of residence: ", @@ -62,17 +60,21 @@ output$EQ1_plot1 <- renderPlotly({ "
", "Mortality rate: ", EQ1_plot1_Data()$risk_ratio))) + - geom_line() + - # guides(linetype = "none", # working on this below in "labs" - # shape = "none", - # # shape = FALSE, - # color = guide_legend(title = "Area name:", - # nrow = 4)) + - scale_color_manual(values = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), - labels = ~ stringr::str_wrap(.x, width = 15)) + - scale_linetype_manual(values = c("solid", "dashed", "solid", "dashed")) + + geom_line()+ geom_point(size = 2.5) + - scale_shape_manual(values = c("circle", "circle", "triangle-up", "triangle-up")) + + aes(group = area_name, + linetype = area_name, # Have to do this outside so that the legends shows and so that there aren't 3 legends + color = area_name, + shape = area_name) + + scale_color_manual(name = "Area name:", + values = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), + labels = ~ stringr::str_wrap(.x, width = 15)) + + scale_linetype_manual(name = "Area name:", + values = c("solid", "dashed", "solid", "dashed"), + labels = ~ stringr::str_wrap(.x, width = 15)) + + scale_shape_manual(name = "Area name:", + values = c("circle", "circle", "triangle-up", "triangle-up"), + labels = ~ stringr::str_wrap(.x, width = 15)) + theme_classic() + # de-clutters graph background theme(panel.grid.major.x = element_line(), # Shows vertical grid lines panel.grid.major.y = element_line(), # Shows horizontal grid lines @@ -81,22 +83,19 @@ output$EQ1_plot1 <- renderPlotly({ face = "bold"), axis.title.y = element_text(size = 12, color = "black", - face = "bold"), - legend.position = "right", # added to test + face = "bold"), legend.text = element_text(size = 8, colour = "black"), legend.title = element_text(size = 9, colour = "black", face = "bold")) + labs(x = "Year", - y = "Mortality Rate", - color = "Area:", - shape = NULL) + + y = "Mortality Rate") + scale_y_continuous(expand = c(0, 0), # Ensures y axis starts from zero limits = c(0, (max(EQ1_plot1_Data()$risk_ratio) + 0.5*max(EQ1_plot1_Data()$risk_ratio)))) }) - - + + ### Run graph 1 through plotly ---- ggplotly(EQ1_plot1_graph(), diff --git a/modules/indicators/EQ1_ui.R b/modules/indicators/EQ1_ui.R index 09431df..ac6ab14 100644 --- a/modules/indicators/EQ1_ui.R +++ b/modules/indicators/EQ1_ui.R @@ -55,7 +55,7 @@ tabItem(tabName = "EQ1_tab", br(), "This is broken down by either council area or health board of ", "residence. Please use the drop down menus to select which ", - "areas you wish to look at."))) + "area you wish to look at."))) ), # Geography Drop Down Menus From 38930f41aebf201144b0a217c59b24a9069d5104 Mon Sep 17 00:00:00 2001 From: MahriScot Date: Fri, 27 Sep 2024 12:20:49 +0100 Subject: [PATCH 57/75] EF4 graph now shows a legend --- modules/indicators/EF4_server.R | 35 +++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/modules/indicators/EF4_server.R b/modules/indicators/EF4_server.R index 834d52d..a412948 100644 --- a/modules/indicators/EF4_server.R +++ b/modules/indicators/EF4_server.R @@ -42,10 +42,6 @@ EF4_trendPlot_data <- reactive({ ggplot(data = EF4_trendPlot_data(), aes(x = fyear, y = value, - group = measure, - color = measure, - linetype = measure, - shape = measure, text = paste0("Financial year: ", # for tooltip in ggplotly - shows values on hover EF4_trendPlot_data()$fyear, "
", @@ -53,26 +49,35 @@ EF4_trendPlot_data <- reactive({ EF4_trendPlot_data()$hb_name, "
", EF4_trendPlot_data()$measure,": ", - EF4_trendPlot_data()$value)) - ) + + EF4_trendPlot_data()$value))) + geom_line() + - guides(linetype = "none", - shape = "none", - color = guide_legend(title = "Measure Name", - nrow = 2)) + - scale_color_manual(values = c("#0078D4", "#3393DD"), # colour for lines - labels = ~ stringr::str_wrap(.x, width = 15)) + - scale_linetype_manual(values = c("solid", "dashed")) + geom_point(size = 2.5) + - scale_shape_manual(values = c("circle", "triangle-up")) + # shape for points + aes(group = measure, # Have to do this outside so that the legends shows and so that there aren't 3 legends + linetype = measure, + color = measure, + shape = measure) + + scale_color_manual(name = "Measure Name", + values = c("#0078D4", "#3393DD"), # colour for lines + labels = ~ stringr::str_wrap(.x, width = 15)) + + scale_linetype_manual(name = "Measure Name", # have to add it into each one or the legend duplicates + values = c("solid", "dashed"), + labels = ~ stringr::str_wrap(.x, width = 15)) + + scale_shape_manual(name = "Measure Name", + values = c("circle", "triangle-up"), # shape for points + labels = ~ stringr::str_wrap(.x, width = 15)) + theme_classic()+ - theme(panel.grid.major.x = element_line(), # Shows vertical grid lines + theme(panel.grid.major.x = element_line(), # Shows vertical grid lines panel.grid.major.y = element_line(), # Shows horizontal grid lines axis.title.x = element_text(size = 12, color = "black", face = "bold"), axis.title.y = element_text(size = 12, color = "black", + face = "bold"), + legend.text = element_text(size = 8, + colour = "black"), + legend.title = element_text(size = 9, + colour = "black", face = "bold")) + labs(x = "Financial Year", y = "Percentage (%)") + From 9deb855fa434af3e189006549265c09e65481021 Mon Sep 17 00:00:00 2001 From: MahriScot Date: Fri, 27 Sep 2024 12:40:19 +0100 Subject: [PATCH 58/75] E1 graph one now shows legend --- modules/indicators/E1_server.R | 89 ++++++++++++++-------------------- 1 file changed, 37 insertions(+), 52 deletions(-) diff --git a/modules/indicators/E1_server.R b/modules/indicators/E1_server.R index d0507f4..1548848 100644 --- a/modules/indicators/E1_server.R +++ b/modules/indicators/E1_server.R @@ -35,9 +35,6 @@ E1_plot1_Data <- reactive({ & area_name %in% input$E1_plot1_areaName) }) -## Add different colours for 5 chosen options ---- - - # Create the discharges line chart ---- @@ -48,13 +45,10 @@ output$E1_plot1 <- renderPlotly({ ### Create reactive ggplot graph ---- E1_plot1_graph <- reactive({ + ggplot(data = E1_plot1_Data(), aes(x = fyear, y = dd_bed_days, - group = area_name, - color = area_name, - linetype = area_name, - shape = area_name, text = paste0("Financial year: ", E1_plot1_Data()$fyear, "
", @@ -62,52 +56,43 @@ output$E1_plot1 <- renderPlotly({ E1_plot1_Data()$area_name, "
", "Total number of bed days: ", - E1_plot1_Data()$dd_bed_days) # for tooltip in ggplotly - shows values on hover - ) - ) + - geom_line() + - guides(linetype = "none", shape = "none", color = guide_legend(title = "Area name", nrow = 2)) + - scale_color_manual(values = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), - labels = ~ stringr::str_wrap(.x, width = 15)) + - scale_linetype_manual(values = c("solid", "dashed", "solid", "dashed")) + - geom_point(size = 2.5) + - scale_shape_manual(values = c("circle", "circle", "triangle-up", "triangle-up")) + - theme_classic() + # I normally use bw but will see what this looks like (de-clutters graph background) - theme(panel.grid.major.x = element_line(), # Shows vertical grid lines - panel.grid.major.y = element_line(), # Shows horizontal grid lines - axis.title.x = element_text(size = 12, - color = "black", - face = "bold"), - axis.title.y = element_text(size = 12, - color = "black", - face = "bold")) + - labs(x = "Financial Year", y = "Total Number of Days") + - scale_y_continuous(expand = c(0, 0), # Ensures y axis starts from zero (important for Orkney and Shetland HBs which are all zero) - limits = c(0, (max(E1_plot1_Data()$dd_bed_days) + 0.5*max(E1_plot1_Data()$dd_bed_days)))) #, - # breaks = seq(0, (max(E1_plot1_Data()$dd_bed_days) + 0.5*max(E1_plot1_Data()$dd_bed_days)), by = 2500)) # Not good for Scotland total. Work on this? - }) + E1_plot1_Data()$dd_bed_days))) + # for tooltip in ggplotly - shows values on hover + geom_line() + + geom_point(size = 2.5) + + aes(group = area_name, + linetype = area_name, + color = area_name, # Have to do this outside so that the legends shows and so that there aren't 3 legends + shape = area_name) + + scale_color_manual(name = "Area name", + values = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), + labels = ~ stringr::str_wrap(.x, width = 15)) + + scale_linetype_manual(name = "Area name", + values = c("solid", "dashed", "solid", "dashed"), + labels = ~ stringr::str_wrap(.x, width = 15)) + + scale_shape_manual(name = "Area name", + values = c("circle", "circle", "triangle-up", "triangle-up"), + labels = ~ stringr::str_wrap(.x, width = 15)) + + theme_classic() + # I normally use bw but will see what this looks like (de-clutters graph background) + theme(panel.grid.major.x = element_line(), # Shows vertical grid lines + panel.grid.major.y = element_line(), # Shows horizontal grid lines + axis.title.x = element_text(size = 12, + color = "black", + face = "bold"), + axis.title.y = element_text(size = 12, + color = "black", + face = "bold"), + legend.text = element_text(size = 8, + colour = "black"), + legend.title = element_text(size = 9, + colour = "black", + face = "bold")) + + labs(x = "Financial Year", + y = "Total Number of Days") + + scale_y_continuous(expand = c(0, 0), # Ensures y axis starts from zero (important for Orkney and Shetland HBs which are all zero) + limits = c(0, (max(E1_plot1_Data()$dd_bed_days) + 0.5*max(E1_plot1_Data()$dd_bed_days)))) + + }) - - # - # geom_line() + - # scale_color_manual(values = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2", "#E6F2FB"))+ - # geom_point(color = "#0080FF", fill = "#0080FF") + - # theme_classic() + # I normally use bw but will see what this looks like (de-clutters graph background) - # theme(panel.grid.major.x = element_line(), # Shows vertical grid lines - # panel.grid.major.y = element_line(), # Shows horizontal grid lines - # axis.title.x = element_text(size = 12, - # color = "black", - # face = "bold"), - # axis.title.y = element_text(size = 12, - # color = "black", - # face = "bold")+ # , - # legend.position = "none") + # removes legend - # labs(x = "Financial Year", y = "Total Number of Days") + - # scale_y_continuous(expand = c(0, 0), # Ensures y axis starts from zero (important for Orkney and Shetland HBs which are all zero) - # limits = c(0, (max(E1_plot1_Data()$dd_bed_days) + 0.5*max(E1_plot1_Data()$dd_bed_days)))) #, - # # breaks = seq(0, (max(E1_plot1_Data()$dd_bed_days) + 0.5*max(E1_plot1_Data()$dd_bed_days)), by = 2500)) # Not good for Scotland total. Work on this? - # }) - ### Run graph 1 through plotly ---- ggplotly(E1_plot1_graph(), From a187ef9ca578a13a761cc98e21ee2259d37296b4 Mon Sep 17 00:00:00 2001 From: MahriScot Date: Fri, 27 Sep 2024 14:19:04 +0100 Subject: [PATCH 59/75] phsstyles colours now used in graphs - E1, EF4, EQ1. --- modules/indicators/E1_server.R | 12 ++++++++---- modules/indicators/EF4_server.R | 9 ++++++--- modules/indicators/EQ1_server.R | 19 ++++++++++++------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/modules/indicators/E1_server.R b/modules/indicators/E1_server.R index 1548848..fdf4223 100644 --- a/modules/indicators/E1_server.R +++ b/modules/indicators/E1_server.R @@ -63,9 +63,12 @@ output$E1_plot1 <- renderPlotly({ linetype = area_name, color = area_name, # Have to do this outside so that the legends shows and so that there aren't 3 legends shape = area_name) + - scale_color_manual(name = "Area name", - values = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), - labels = ~ stringr::str_wrap(.x, width = 15)) + + scale_color_discrete_phs(name = "Area name", + palette = "main-blues", + labels = ~ stringr::str_wrap(.x, width = 15)) + + # scale_color_manual(name = "Area name", + # values = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), + # labels = ~ stringr::str_wrap(.x, width = 15)) + scale_linetype_manual(name = "Area name", values = c("solid", "dashed", "solid", "dashed"), labels = ~ stringr::str_wrap(.x, width = 15)) + @@ -322,7 +325,8 @@ E1_plot2_graph <- reactive({ "Bed days per 1,000 population: ", rate_per_1000_population) )) + geom_bar(stat = "identity") + # creates bar graph with bars separated from each other - scale_fill_manual(values = c("#0080FF", "seagreen")) + # highlights NHS Scotland + scale_fill_manual(values = phs_colours(c("phs-blue", "phs-green"))) + # highlights NHS Scotland +# scale_fill_manual(values = c("#0080FF", "seagreen")) + # highlights NHS Scotland theme_classic() + # I normally use bw but will see what this looks like (de-clutters graph background) theme(panel.grid.major.x = element_line(), # Shows vertical grid lines panel.grid.major.y = element_line(), # Shows horizontal grid lines diff --git a/modules/indicators/EF4_server.R b/modules/indicators/EF4_server.R index a412948..c2f7c29 100644 --- a/modules/indicators/EF4_server.R +++ b/modules/indicators/EF4_server.R @@ -56,9 +56,12 @@ EF4_trendPlot_data <- reactive({ linetype = measure, color = measure, shape = measure) + - scale_color_manual(name = "Measure Name", - values = c("#0078D4", "#3393DD"), # colour for lines - labels = ~ stringr::str_wrap(.x, width = 15)) + + scale_color_discrete_phs(name = "Measure Name", + palette = "main-blues", + labels = ~ stringr::str_wrap(.x, width = 15)) + + # scale_color_manual(name = "Measure Name", + # values = c("#0078D4", "#3393DD"), # colour for lines + # labels = ~ stringr::str_wrap(.x, width = 15)) + scale_linetype_manual(name = "Measure Name", # have to add it into each one or the legend duplicates values = c("solid", "dashed"), labels = ~ stringr::str_wrap(.x, width = 15)) + diff --git a/modules/indicators/EQ1_server.R b/modules/indicators/EQ1_server.R index 82cbdb7..eab952b 100644 --- a/modules/indicators/EQ1_server.R +++ b/modules/indicators/EQ1_server.R @@ -47,8 +47,9 @@ output$EQ1_plot1 <- renderPlotly({ ### Create reactive ggplot graph ---- - #testing to add legend!! + EQ1_plot1_graph <- reactive({ + ggplot(data = EQ1_plot1_Data(), aes(x = Year, y = risk_ratio, @@ -66,13 +67,16 @@ output$EQ1_plot1 <- renderPlotly({ linetype = area_name, # Have to do this outside so that the legends shows and so that there aren't 3 legends color = area_name, shape = area_name) + - scale_color_manual(name = "Area name:", - values = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), - labels = ~ stringr::str_wrap(.x, width = 15)) + - scale_linetype_manual(name = "Area name:", + scale_color_discrete_phs(name = "Area name", + palette = "main-blues", + labels = ~ stringr::str_wrap(.x, width = 15)) + + # scale_color_manual(name = "Area name:", + # values = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), # MS 27/09 - keeping this in for now - until spoken about phsstyles + # labels = ~ stringr::str_wrap(.x, width = 15)) + + scale_linetype_manual(name = "Area name", values = c("solid", "dashed", "solid", "dashed"), labels = ~ stringr::str_wrap(.x, width = 15)) + - scale_shape_manual(name = "Area name:", + scale_shape_manual(name = "Area name", values = c("circle", "circle", "triangle-up", "triangle-up"), labels = ~ stringr::str_wrap(.x, width = 15)) + theme_classic() + # de-clutters graph background @@ -173,7 +177,8 @@ output$EQ1_plot4 <- renderPlotly({ EQ1_plot4_Data()$Rate) )) + geom_bar(stat = "identity", position = "dodge") + # creates bar graph with bars separated from each other - scale_fill_manual(values = c("#0078D4", "#B3D7F2")) + + #scale_fill_manual(values = c("#0078D4", "#B3D7F2")) + # MS 27/09 - keep until phsstyles have been spoken about + scale_fill_manual(values = phs_colours(c("phs-blue", "phs-blue-50"))) + theme_classic() + theme(#legend.position = "bottom", # WHY ISN'T THIS WORKING? panel.grid.major.x = element_line(), # Shows vertical grid lines From ea95bcec32524b717d1fb4b655f60797a4e364b7 Mon Sep 17 00:00:00 2001 From: MahriScot Date: Fri, 27 Sep 2024 14:20:36 +0100 Subject: [PATCH 60/75] Added some spacing between page titles and graphs. --- modules/indicators/E1_ui.R | 7 +++++-- modules/indicators/EF4_ui.R | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/indicators/E1_ui.R b/modules/indicators/E1_ui.R index b3be1a7..9fbd5e4 100644 --- a/modules/indicators/E1_ui.R +++ b/modules/indicators/E1_ui.R @@ -18,6 +18,9 @@ tabItem(tabName = "E1_tab", "when they are clinically ready to be discharged (per 1,000 population)") ), + + hr(), # page break + ## First Graph ---- # Text above graph fluidRow( @@ -51,9 +54,9 @@ tabItem(tabName = "E1_tab", ) ), - br(), + hr(), # page break - br(), + ## Second Graph ---- # Text above graph diff --git a/modules/indicators/EF4_ui.R b/modules/indicators/EF4_ui.R index b12bf79..3afcd0a 100644 --- a/modules/indicators/EF4_ui.R +++ b/modules/indicators/EF4_ui.R @@ -3,6 +3,8 @@ tabItem(tabName = "EF4_tab", # Defining the title h1("EF4 - Total mental health spend as a % of total spend"), + hr(), # page break + ## Text Above Graph ---- fluidRow( column(12, From bfabddbf3fe7027f8db401bca6f2502122b04c3f Mon Sep 17 00:00:00 2001 From: Cormac-Murray Date: Tue, 1 Oct 2024 10:21:59 +0100 Subject: [PATCH 61/75] Create data tables on E1 page, along with option to download. --- app.R | 1 + modules/indicators/E1_server.R | 70 +++++++++++++++++++++++++++++----- modules/indicators/E1_ui.R | 61 +++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+), 10 deletions(-) diff --git a/app.R b/app.R index c23740b..db33d20 100644 --- a/app.R +++ b/app.R @@ -14,6 +14,7 @@ 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) # Data import section ---------------------------------------------------- diff --git a/modules/indicators/E1_server.R b/modules/indicators/E1_server.R index fdf4223..cf0d0ea 100644 --- a/modules/indicators/E1_server.R +++ b/modules/indicators/E1_server.R @@ -264,16 +264,17 @@ output$E1_plot1 <- renderPlotly({ # # ### 15 - Table below graph creation ---- # -# # output$E1_1_trend_table <- renderDataTable({ -# # datatable(E1_plot1_Data(), -# # style = 'bootstrap', -# # class = 'table-bordered table-condensed', -# # rownames = FALSE, -# # options = list(pageLength = 16, autoWidth = TRUE, dom = 'tip'), -# # colnames = c("Financial year", -# # "Area of Residence", -# # "Number of Bed Days")) -# # }) + output$E1_1_table <- renderDataTable({ + datatable(E1_plot1_Data(), + style = 'bootstrap', + class = 'table-bordered table-condensed', + rownames = FALSE, + options = list(pageLength = 16, autoWidth = TRUE, dom = 'tip'), + colnames = c("Financial year", + "Area type", + "Area of Residence", + "Number of Bed Days")) + }) @@ -352,6 +353,55 @@ ggplotly(E1_plot2_graph(), }) +# ### 15 - Table below graph creation ---- +# +output$E1_2_table <- renderDataTable({ + datatable(E1_plot2_Data(), + style = 'bootstrap', + class = 'table-bordered table-condensed', + rownames = FALSE, + options = list(pageLength = 16, autoWidth = TRUE, dom = 'tip', + columnDefs = list(list(visible=FALSE, targets=5))), + colnames = c("Financial year", + "Area type", + "Area of Residence", + "Number of Bed Days", + "Rate per 1000 population", + "Highlight")) +}) + +# Create download buttons that allows users to the download tables in .csv format. +output$E1_1_table_download <- downloadHandler( + filename = 'E1_Table1.csv', + content = function(file) { + write.table(E1_plot1_Data(), + file, + #Remove row numbers as the .csv file already has row numbers. + row.names = FALSE, + col.names = c("Financial year", + "Area type", + "Area of Residence", + "Number of Bed Days"), + sep = ",") + } +) + +output$E1_2_table_download <- downloadHandler( + filename = 'E1_Table2.csv', + content = function(file) { + write.table(E1_plot2_Data(), + file, + #Remove row numbers as the .csv file already has row numbers. + row.names = FALSE, + col.names = c("Financial year", + "Area type", + "Area of Residence", + "Number of Bed Days", + "Rate per 1000 population", + "Highlight"), + sep = ",") + } +) ## x OLD PLOTLY CODE - PLOT 2 ---- diff --git a/modules/indicators/E1_ui.R b/modules/indicators/E1_ui.R index 9fbd5e4..18b4118 100644 --- a/modules/indicators/E1_ui.R +++ b/modules/indicators/E1_ui.R @@ -86,6 +86,67 @@ tabItem(tabName = "E1_tab", ) ), + hr(), # page break + + fluidRow( + column(12, + box(width = NULL, + p(paste0( + "The first graph's data is presented in the table below.")) + ) + ) + ), # End of fluidRow + # Table with graph 1 data + fluidRow( + box(width = 12, + dataTableOutput("E1_1_table") + ) + ), + + fluidRow( + column(4, + downloadButton(outputId = "E1_1_table_download", + label = "Download as .csv", + class = "E1_1_table_downloadbutton"), + tags$head( + tags$style(".E1_1_table_downloadbutton { background-color: + #3F3685; } + .E1_1_table_downloadbutton { color: #FFFFFF; }") + ) + ) + ), + + hr(), + + fluidRow( + column(12, + box(width = NULL, + p(paste0( + "The second graph's data is presented in the table below.")) + ) + ) + ), # End of fluidRow + # Table with graph 2 data + fluidRow( + box(width = 12, + dataTableOutput("E1_2_table") + ) + ), + + fluidRow( + column(4, + downloadButton(outputId = "E1_2_table_download", + label = "Download as .csv", + class = "E1_2_table_downloadbutton"), + tags$head( + tags$style(".E1_2_table_downloadbutton { background-color: + #3F3685; } + .E1_2_table_downloadbutton { color: #FFFFFF; }") + ) + ) + ), + + # mainPanel( # tags$p("Below is a graph showing the changes over time."), From 12e3bf5ec9c615127dd36532d54082c867658376 Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Tue, 1 Oct 2024 13:19:03 +0100 Subject: [PATCH 62/75] Added borders to Scot Hub boxes and changed box header colour --- .gitignore | 5 ++++- www/stylesheet.css | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index caafb14..b559259 100644 --- a/.gitignore +++ b/.gitignore @@ -9,14 +9,17 @@ # Deployment secrets # Credentials script +create_credentials.R # Constants file constants.R # folders to ignrore +admin/ +archive/ data/ drafts/ www/infographics -archive/ + # Common text files that may contain data # *.[cC][sS][vV] diff --git a/www/stylesheet.css b/www/stylesheet.css index a8680cb..6db5301 100755 --- a/www/stylesheet.css +++ b/www/stylesheet.css @@ -66,26 +66,29 @@ h1 { .col-sm-4{ min-width: 400px; } -/* -.box .box-solid{ - width: 400px; -}*/ +/* Box border */ +.box{ + border-width: thin; + border-style: solid; + border-color: #C5C3DA; +} /* Header */ .box-header{ - background-color: #3F3685; /* Header colour */ - color: #ECEBF3; /* Header text colour */ + background-color: #ECEBF3; /* Header colour */ + color: #3F3685; /* Header text colour */ /*font-weight: bold;*/ word-wrap: normal; /* tell css to wrap the text in buttons */ white-space: normal; /* required for text wrapping to work */ height: 90px; /* Specifying height of Header area */ + border: thin solid #C5C3DA; } /* Box Header Text */ .box-header h3{ - /* font-weight: bold; */ - + /* */ font-size: 36px; + font-weight: bold; /*line-height: 3; Doesn't seem to change anything */ } From 29cfc25aa84df647179bc3f57389ceafcf384ef4 Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Tue, 1 Oct 2024 13:46:33 +0100 Subject: [PATCH 63/75] Changed Scot Hub header colour to phs teal 10% --- www/stylesheet.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/stylesheet.css b/www/stylesheet.css index 6db5301..b59b38e 100755 --- a/www/stylesheet.css +++ b/www/stylesheet.css @@ -75,7 +75,7 @@ h1 { /* Header */ .box-header{ - background-color: #ECEBF3; /* Header colour */ + background-color: #E9F2F3; /* Header colour */ color: #3F3685; /* Header text colour */ /*font-weight: bold;*/ word-wrap: normal; /* tell css to wrap the text in buttons */ From e616ff0922697f18a15625811388c0f90688c91c Mon Sep 17 00:00:00 2001 From: Cormac-Murray Date: Tue, 1 Oct 2024 15:52:12 +0100 Subject: [PATCH 64/75] Put E1 tables within collapsed boxes. --- modules/indicators/E1_ui.R | 153 ++++++++++++++++++++++++++----------- 1 file changed, 109 insertions(+), 44 deletions(-) diff --git a/modules/indicators/E1_ui.R b/modules/indicators/E1_ui.R index 18b4118..bc75e10 100644 --- a/modules/indicators/E1_ui.R +++ b/modules/indicators/E1_ui.R @@ -54,6 +54,37 @@ tabItem(tabName = "E1_tab", ) ), + hr(), # page break + + # fluidRow( + # column(12, + # box(width = NULL, + # p(paste0( + # "The first graph's data is presented in the table below.")) + # ) + # ) + # ), # End of fluidRow + # Table with graph 1 data + fluidRow( + box(title = "This section can be expanded to view the data in the graph above as a table.", + width = 12, solidHeader = TRUE, collapsible = TRUE, collapsed = TRUE, + dataTableOutput("E1_1_table") + ) + ), + + fluidRow( + column(4, + downloadButton(outputId = "E1_1_table_download", + label = "Download as .csv", + class = "E1_1_table_downloadbutton"), + tags$head( + tags$style(".E1_1_table_downloadbutton { background-color: + #3F3685; } + .E1_1_table_downloadbutton { color: #FFFFFF; }") + ) + ) + ), + hr(), # page break @@ -88,66 +119,100 @@ tabItem(tabName = "E1_tab", hr(), # page break - fluidRow( - column(12, - box(width = NULL, - p(paste0( - "The first graph's data is presented in the table below.")) - ) - ) - ), # End of fluidRow - # Table with graph 1 data - fluidRow( - box(width = 12, - dataTableOutput("E1_1_table") - ) - ), - - fluidRow( - column(4, - downloadButton(outputId = "E1_1_table_download", - label = "Download as .csv", - class = "E1_1_table_downloadbutton"), - tags$head( - tags$style(".E1_1_table_downloadbutton { background-color: - #3F3685; } - .E1_1_table_downloadbutton { color: #FFFFFF; }") - ) - ) - ), - - hr(), - fluidRow( - column(12, - box(width = NULL, - p(paste0( - "The second graph's data is presented in the table below.")) - ) - ) - ), # End of fluidRow + # hr(), + # + # fluidRow( + # column(12, + # box(width = NULL, + # p(paste0( + # "The second graph's data is presented in the table below.")) + # ) + # ) + # ), # End of fluidRow # Table with graph 2 data fluidRow( - box(width = 12, + box(title = "This section can be expanded to view the data in the graph above as a table.", + width = 12, solidHeader = TRUE, collapsible = TRUE, collapsed = TRUE, dataTableOutput("E1_2_table") ) ), fluidRow( column(4, - downloadButton(outputId = "E1_2_table_download", - label = "Download as .csv", - class = "E1_2_table_downloadbutton"), - tags$head( - tags$style(".E1_2_table_downloadbutton { background-color: + downloadButton(outputId = "E1_2_table_download", + label = "Download as .csv", + class = "E1_2_table_downloadbutton"), + tags$head( + tags$style(".E1_2_table_downloadbutton { background-color: #3F3685; } .E1_2_table_downloadbutton { color: #FFFFFF; }") - ) + ) ) ), + # fluidRow( + # column(12, + # box(width = NULL, + # p(paste0( + # "The first graph's data is presented in the table below.")) + # ) + # ) + # ), # End of fluidRow + # # Table with graph 1 data + # fluidRow( + # box(width = 12, solidHeader = TRUE, collapsible = TRUE, + # dataTableOutput("E1_1_table") + # ) + # ), + # + # fluidRow( + # column(4, + # downloadButton(outputId = "E1_1_table_download", + # label = "Download as .csv", + # class = "E1_1_table_downloadbutton"), + # tags$head( + # tags$style(".E1_1_table_downloadbutton { background-color: + # #3F3685; } + # .E1_1_table_downloadbutton { color: #FFFFFF; }") + # ) + # ) + # ), + # + # hr(), + # + # fluidRow( + # column(12, + # box(width = NULL, + # p(paste0( + # "The second graph's data is presented in the table below.")) + # ) + # ) + # ), # End of fluidRow + # # Table with graph 2 data + # fluidRow( + # box(width = 12, solidHeader = TRUE, collapsible = TRUE, collapsed = TRUE, + # dataTableOutput("E1_2_table") + # ) + # ), + # + # fluidRow( + # column(4, + # downloadButton(outputId = "E1_2_table_download", + # label = "Download as .csv", + # class = "E1_2_table_downloadbutton"), + # tags$head( + # tags$style(".E1_2_table_downloadbutton { background-color: + # #3F3685; } + # .E1_2_table_downloadbutton { color: #FFFFFF; }") + # ) + # ) + # ), + + + # mainPanel( # tags$p("Below is a graph showing the changes over time."), # From 177281340120221481f6dc2b826f1b5d89158e33 Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Tue, 1 Oct 2024 17:46:00 +0100 Subject: [PATCH 65/75] Added password protection --- app.R | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/app.R b/app.R index db33d20..1d5cd8c 100644 --- a/app.R +++ b/app.R @@ -27,9 +27,12 @@ source("data_preparation.R") list.files("functions") %>% map(~ source(paste0("functions/", .))) -# Source the ui files ---- +#* Read in credentials for password-protecting the app ---- +# credentials <- readRDS("admin/credentials.rds") # Un-comment if password protection needed -# ui <- source('ui.R', local = TRUE)$value +### [ UI section ] ------------------------------------------------------------- + +# secure_app( # Un-comment if password protection is needed. ui <- dashboardPage( @@ -39,6 +42,7 @@ ui <- dashboardPage( # 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, @@ -55,7 +59,7 @@ ui <- dashboardPage( # [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, @@ -93,10 +97,23 @@ ui <- dashboardPage( ) # End of tabItems ) # End of dashboardBody ) # End of UI +# ) # 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) From c4c77260db720cac895a2a09b56337ccc8ae55ef Mon Sep 17 00:00:00 2001 From: Cormac-Murray Date: Wed, 2 Oct 2024 15:02:50 +0100 Subject: [PATCH 66/75] Remove highlight column from second E1 downloadable table. --- modules/indicators/E1_server.R | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/indicators/E1_server.R b/modules/indicators/E1_server.R index cf0d0ea..d9e4fbd 100644 --- a/modules/indicators/E1_server.R +++ b/modules/indicators/E1_server.R @@ -302,8 +302,14 @@ E1_plot2_Data <- reactive({ mutate(to_highlight = if_else(area_name == "NHS Scotland", # for highlighting NHS Scotland "seagreen", "#0080FF")) # changed from "yes" and "no" so that these colours }) # appear on the graph and don't have a legend using "marker = list(color... )" - # Note: only using "seagreen" to make sure it is working for now, can change colour later + +E1_plot2_Data_download <- reactive({ #Equivalent data for download function, without highlight column. + E1_data %>% + select(fyear, area_type, area_name, dd_bed_days, rate_per_1000_population) %>% + filter(area_type == "Health board") %>% + filter(fyear %in% input$E1_plot2_year) %>% + mutate(area_name = fct_reorder(area_name, rate_per_1000_population)) }) # Create the discharges bar chart ---- @@ -389,7 +395,7 @@ output$E1_1_table_download <- downloadHandler( output$E1_2_table_download <- downloadHandler( filename = 'E1_Table2.csv', content = function(file) { - write.table(E1_plot2_Data(), + write.table(E1_plot2_Data_download(), file, #Remove row numbers as the .csv file already has row numbers. row.names = FALSE, @@ -397,8 +403,7 @@ output$E1_2_table_download <- downloadHandler( "Area type", "Area of Residence", "Number of Bed Days", - "Rate per 1000 population", - "Highlight"), + "Rate per 1000 population"), sep = ",") } ) From 976294b8719eea1a600deef856a511422c93cb3e Mon Sep 17 00:00:00 2001 From: Cormac-Murray Date: Thu, 3 Oct 2024 10:40:47 +0100 Subject: [PATCH 67/75] Adding tables and download option to EF4. --- modules/indicators/EF4_server.R | 39 +++++++++++++++++++++++---------- modules/indicators/EF4_ui.R | 25 +++++++++++++++++++++ 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/modules/indicators/EF4_server.R b/modules/indicators/EF4_server.R index c2f7c29..a32875d 100644 --- a/modules/indicators/EF4_server.R +++ b/modules/indicators/EF4_server.R @@ -102,18 +102,35 @@ EF4_trendPlot_data <- reactive({ ### Table below graph ---- - # output$EF4_1_trend_table <- renderDataTable({ - # datatable(EF4_trendPlot_data(), - # style = 'bootstrap', - # class = 'table-bordered table-condensed', - # rownames = FALSE, - # options = list(pageLength = 16, autoWidth = TRUE, dom = 'tip'), - # colnames = c("Financial year", - # "Area of Residence", - # "Number of Bed Days")) - # }) - + output$EF4_table <- renderDataTable({ + datatable(EF4_trendPlot_data(), + style = 'bootstrap', + class = 'table-bordered table-condensed', + rownames = FALSE, + options = list(pageLength = 16, autoWidth = TRUE, dom = 'tip'), + colnames = c("Financial year", + "Health Board", + "Measure Name", + "Value")) + }) + # Create download button that allows users to download tables in .csv format. + output$EF4_table_download <- downloadHandler( + filename = 'EF4_Table1.csv', + content = function(file) { + write.table(EF4_trendPlot_data(), + file, + #Remove row numbers as the .csv file already has row numbers. + row.names = FALSE, + col.names = c("Financial year", + "Health Board", + "Measure Name", + "Value"), + sep = ",") + } + ) + + # X OLD CODE ---- # diff --git a/modules/indicators/EF4_ui.R b/modules/indicators/EF4_ui.R index 3afcd0a..1cb01dc 100644 --- a/modules/indicators/EF4_ui.R +++ b/modules/indicators/EF4_ui.R @@ -36,6 +36,31 @@ tabItem(tabName = "EF4_tab", # height = "50vh", width = "100%")) ), + hr(), # page break + + fluidRow( + box(title = "This section can be expanded to view the data in the graph above as a table.", + width = 12, solidHeader = TRUE, collapsible = TRUE, collapsed = TRUE, + dataTableOutput("EF4_table") + ) + ), + fluidRow( + column(4, + downloadButton(outputId = "EF4_table_download", + label = "Download as .csv", + class = "EF4_table_downloadbutton"), + tags$head( + tags$style(".EF4_table_downloadbutton { background-color: + #3F3685; } + .EF4_table_downloadbutton { color: #FFFFFF; }") + ) + ) + ), + + + hr(), # page break + + fluidRow( column(12, box(width = NULL, From a93b3b259c935c51fbf4b294cd43047849fce84a Mon Sep 17 00:00:00 2001 From: Cormac-Murray Date: Thu, 3 Oct 2024 13:27:07 +0100 Subject: [PATCH 68/75] Create tables and download buttons for EQ1. --- modules/indicators/EQ1_server.R | 625 +++++++++++++++++++------------- modules/indicators/EQ1_ui.R | 334 +++++++++-------- 2 files changed, 560 insertions(+), 399 deletions(-) diff --git a/modules/indicators/EQ1_server.R b/modules/indicators/EQ1_server.R index eab952b..86e645e 100644 --- a/modules/indicators/EQ1_server.R +++ b/modules/indicators/EQ1_server.R @@ -1,13 +1,14 @@ # PLOT 1 ---- -## Picker for selecting HB or CA ---- +## Picker for selecting HB or CA ---- output$EQ1_plot1_areaType_output <- renderUI({ shinyWidgets::pickerInput( "EQ1_plot1_areaType", label = "Select type of geography:", choices = unique_area_types, - selected = "Health board") + selected = "Health board" + ) }) ## Picker for user selecting specific geographies ---- @@ -22,195 +23,326 @@ output$EQ1_plot1_areaName_output <- renderUI({ ))) , multiple = TRUE, - options = list("max-options" = 4, - `selected-text-format` = "count > 1"), + options = list( + "max-options" = 4, + `selected-text-format` = "count > 1" + ), selected = "NHS Ayrshire and Arran" ) }) -## Selecting appropriate data for graph 1 ---- +## Selecting appropriate data for graph 1 ---- EQ1_plot1_Data <- reactive({ EQ1_data %>% - select(Year, area_type, area_name, risk_ratio, SMR04_Pop_Rate, General_Pop_Rate) %>% - mutate(risk_ratio = round(risk_ratio, 2)) %>% # because values are e.g., "5.239755" + select(Year, + area_type, + area_name, + risk_ratio, + SMR04_Pop_Rate, + General_Pop_Rate) %>% + mutate(risk_ratio = round(risk_ratio, 2)) %>% # because values are e.g., "5.239755" filter(area_type %in% input$EQ1_plot1_areaType & area_name %in% input$EQ1_plot1_areaName) }) -# Create the risk ratios line chart ---- +# Create the risk ratios line chart ---- - ### Render Plotly ---- +### Render Plotly ---- output$EQ1_plot1 <- renderPlotly({ - - - ### Create reactive ggplot graph ---- - - EQ1_plot1_graph <- reactive({ - - ggplot(data = EQ1_plot1_Data(), - aes(x = Year, - y = risk_ratio, - text = paste0("Financial year: ", # for tooltip in ggplotly - shows values on hover - EQ1_plot1_Data()$Year, - "
", - "Area of residence: ", - EQ1_plot1_Data()$area_name, - "
", - "Mortality rate: ", - EQ1_plot1_Data()$risk_ratio))) + - geom_line()+ - geom_point(size = 2.5) + - aes(group = area_name, - linetype = area_name, # Have to do this outside so that the legends shows and so that there aren't 3 legends - color = area_name, - shape = area_name) + - scale_color_discrete_phs(name = "Area name", - palette = "main-blues", - labels = ~ stringr::str_wrap(.x, width = 15)) + - # scale_color_manual(name = "Area name:", - # values = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), # MS 27/09 - keeping this in for now - until spoken about phsstyles - # labels = ~ stringr::str_wrap(.x, width = 15)) + - scale_linetype_manual(name = "Area name", - values = c("solid", "dashed", "solid", "dashed"), - labels = ~ stringr::str_wrap(.x, width = 15)) + - scale_shape_manual(name = "Area name", - values = c("circle", "circle", "triangle-up", "triangle-up"), - labels = ~ stringr::str_wrap(.x, width = 15)) + - theme_classic() + # de-clutters graph background - theme(panel.grid.major.x = element_line(), # Shows vertical grid lines - panel.grid.major.y = element_line(), # Shows horizontal grid lines - axis.title.x = element_text(size = 12, - color = "black", - face = "bold"), - axis.title.y = element_text(size = 12, - color = "black", - face = "bold"), - legend.text = element_text(size = 8, - colour = "black"), - legend.title = element_text(size = 9, - colour = "black", - face = "bold")) + - labs(x = "Year", - y = "Mortality Rate") + - scale_y_continuous(expand = c(0, 0), # Ensures y axis starts from zero - limits = c(0, (max(EQ1_plot1_Data()$risk_ratio) + 0.5*max(EQ1_plot1_Data()$risk_ratio)))) - }) - - - ### Run graph 1 through plotly ---- - - ggplotly(EQ1_plot1_graph(), - tooltip = "text")#, # uses text set up in ggplot aes above. - # ### Remove unnecessary buttons from the modebar ---- not working just now - # config(displayModeBar = TRUE, # Remove unnecessary buttons from the modebar - # modeBarButtonsToRemove = bttn_remove, - # displaylogo = F, editable = F)) - + ### Create reactive ggplot graph ---- + + EQ1_plot1_graph <- reactive({ + ggplot(data = EQ1_plot1_Data(), + aes( + x = Year, + y = risk_ratio, + text = paste0( + "Financial year: ", + # for tooltip in ggplotly - shows values on hover + EQ1_plot1_Data()$Year, + "
", + "Area of residence: ", + EQ1_plot1_Data()$area_name, + "
", + "Mortality rate: ", + EQ1_plot1_Data()$risk_ratio + ) + )) + + geom_line() + + geom_point(size = 2.5) + + aes( + group = area_name, + linetype = area_name, + # Have to do this outside so that the legends shows and so that there aren't 3 legends + color = area_name, + shape = area_name + ) + + scale_color_discrete_phs( + name = "Area name", + palette = "main-blues", + labels = ~ stringr::str_wrap(.x, width = 15) + ) + + # scale_color_manual(name = "Area name:", + # values = c("#0078D4", "#3393DD", "#80BCEA", "#B3D7F2"), # MS 27/09 - keeping this in for now - until spoken about phsstyles + # labels = ~ stringr::str_wrap(.x, width = 15)) + + scale_linetype_manual( + name = "Area name", + values = c("solid", "dashed", "solid", "dashed"), + labels = ~ stringr::str_wrap(.x, width = 15) + ) + + scale_shape_manual( + name = "Area name", + values = c("circle", "circle", "triangle-up", "triangle-up"), + labels = ~ stringr::str_wrap(.x, width = 15) + ) + + theme_classic() + # de-clutters graph background + theme( + panel.grid.major.x = element_line(), + # Shows vertical grid lines + panel.grid.major.y = element_line(), + # Shows horizontal grid lines + axis.title.x = element_text( + size = 12, + color = "black", + face = "bold" + ), + axis.title.y = element_text( + size = 12, + color = "black", + face = "bold" + ), + legend.text = element_text(size = 8, + colour = "black"), + legend.title = element_text( + size = 9, + colour = "black", + face = "bold" + ) + ) + + labs(x = "Year", + y = "Mortality Rate") + + scale_y_continuous(expand = c(0, 0), # Ensures y axis starts from zero + limits = c(0, ( + max(EQ1_plot1_Data()$risk_ratio) + 0.5 * max(EQ1_plot1_Data()$risk_ratio) + ))) + }) + + + ### Run graph 1 through plotly ---- + + ggplotly(EQ1_plot1_graph(), + tooltip = "text")#, # uses text set up in ggplot aes above. + # ### Remove unnecessary buttons from the modebar ---- not working just now + # config(displayModeBar = TRUE, # Remove unnecessary buttons from the modebar + # modeBarButtonsToRemove = bttn_remove, + # displaylogo = F, editable = F)) + }) - + # EQ1 PLOT 2 ---- ## Picker for user selecting HB or CA ---- - + output$EQ1_plot4_areaType_output <- renderUI({ - shinyWidgets::pickerInput( - "EQ1_plot4_areaType", - label = "Select type of geography:", - choices = unique_area_types, - selected = "Health board") + shinyWidgets::pickerInput( + "EQ1_plot4_areaType", + label = "Select type of geography:", + choices = unique_area_types, + selected = "Health board" + ) }) ## Picker for user selecting specific geographies ---- output$EQ1_plot4_areaName_output <- renderUI({ - shinyWidgets::pickerInput( - "EQ1_plot4_areaName", - label = "Select area:", - choices = sort(unique(as.character( - EQ1_reformatted_data$area_name - [EQ1_reformatted_data$area_type %in% input$EQ1_plot4_areaType] - ))), - multiple = TRUE, - options = list("max-options" = 1, - `selected-text-format` = "count > 1"), - selected = "NHS Ayrshire and Arran") + shinyWidgets::pickerInput( + "EQ1_plot4_areaName", + label = "Select area:", + choices = sort(unique( + as.character(EQ1_reformatted_data$area_name + [EQ1_reformatted_data$area_type %in% input$EQ1_plot4_areaType]) + )), + multiple = TRUE, + options = list( + "max-options" = 1, + `selected-text-format` = "count > 1" + ), + selected = "NHS Ayrshire and Arran" + ) }) -## Selecting appropriate data for graph 2 ---- +## Selecting appropriate data for graph 2 ---- EQ1_plot4_Data <- reactive({ - EQ1_reformatted_data %>% - select(Rate_Type, Year, area_type, area_name, Rate) %>% - filter(area_type %in% input$EQ1_plot4_areaType - & area_name %in% input$EQ1_plot4_areaName) + EQ1_reformatted_data %>% + select(Rate_Type, Year, area_type, area_name, Rate) %>% + filter(area_type %in% input$EQ1_plot4_areaType + & area_name %in% input$EQ1_plot4_areaName) }) # Create the combined general population and MH rates bar chart ---- - ### Render plotly ---- +### Render plotly ---- output$EQ1_plot4 <- renderPlotly({ + ### Create reactive ggplot bar graph ---- + + EQ1_plot4_graph <- reactive({ + ggplot(data = EQ1_plot4_Data(), + aes( + x = Year, + y = Rate, + fill = Rate_Type, + # colours defined below + text = paste0( + "Financial year: ", + EQ1_plot4_Data()$Year, + "
", + "Area of residence: ", + EQ1_plot4_Data()$area_name, + "
", + "Rate Type: ", + EQ1_plot4_Data()$Rate_Type, + "
", + "Rate: ", + EQ1_plot4_Data()$Rate + ) + )) + + geom_bar(stat = "identity", position = "dodge") + # creates bar graph with bars separated from each other + #scale_fill_manual(values = c("#0078D4", "#B3D7F2")) + # MS 27/09 - keep until phsstyles have been spoken about + scale_fill_manual(values = phs_colours(c("phs-blue", "phs-blue-50"))) + + theme_classic() + + theme( + #legend.position = "bottom", # WHY ISN'T THIS WORKING? + panel.grid.major.x = element_line(), + # Shows vertical grid lines + panel.grid.major.y = element_line(), + # Shows horizontal grid lines + axis.title.x = element_text( + size = 12, + color = "black", + face = "bold" + ), + axis.title.y = element_text( + size = 12, + color = "black", + face = "bold" + ) + ) + + labs(x = "Year", + y = "Mortality Rate", + fill = "Population Group:") + + scale_y_continuous(expand = c(0, 0), # Ensures y axis starts from zero + limits = c(0, ( + max(EQ1_plot4_Data()$Rate) + 0.5 * max(EQ1_plot4_Data()$Rate) + ))) + + }) + + + ### Run graph 2 through plotly ---- + + ggplotly(EQ1_plot4_graph(), + tooltip = "text")#, # uses text set up in ggplot aes above. + # ### Remove unnecessary buttons from the modebar ---- not working but will make work + # config(displayModeBar = TRUE, + # modeBarButtonsToRemove = bttn_remove, + # displaylogo = F, editable = F)) + +}) + - ### Create reactive ggplot bar graph ---- - - EQ1_plot4_graph <- reactive({ - ggplot(data = EQ1_plot4_Data(), - aes(x = Year, - y = Rate, - fill = Rate_Type, # colours defined below - text = paste0("Financial year: ", - EQ1_plot4_Data()$Year, - "
", - "Area of residence: ", - EQ1_plot4_Data()$area_name, - "
", - "Rate Type: ", - EQ1_plot4_Data()$Rate_Type, - "
", - "Rate: ", - EQ1_plot4_Data()$Rate) - )) + - geom_bar(stat = "identity", position = "dodge") + # creates bar graph with bars separated from each other - #scale_fill_manual(values = c("#0078D4", "#B3D7F2")) + # MS 27/09 - keep until phsstyles have been spoken about - scale_fill_manual(values = phs_colours(c("phs-blue", "phs-blue-50"))) + - theme_classic() + - theme(#legend.position = "bottom", # WHY ISN'T THIS WORKING? - panel.grid.major.x = element_line(), # Shows vertical grid lines - panel.grid.major.y = element_line(), # Shows horizontal grid lines - axis.title.x = element_text(size = 12, - color = "black", - face = "bold"), - axis.title.y = element_text(size = 12, - color = "black", - face = "bold")) + - labs(x = "Year", - y = "Mortality Rate", - fill = "Population Group:") + - scale_y_continuous(expand = c(0, 0), # Ensures y axis starts from zero - limits = c(0, (max(EQ1_plot4_Data()$Rate) + 0.5*max(EQ1_plot4_Data()$Rate)))) - - }) - - -### Run graph 2 through plotly ---- - - ggplotly(EQ1_plot4_graph(), - tooltip = "text")#, # uses text set up in ggplot aes above. - # ### Remove unnecessary buttons from the modebar ---- not working but will make work - # config(displayModeBar = TRUE, - # modeBarButtonsToRemove = bttn_remove, - # displaylogo = F, editable = F)) - +### Tables below graphs ---- +# Year, area_type, area_name, risk_ratio, SMR04_Pop_Rate, General_Pop_Rate +output$EQ1_1_table <- renderDataTable({ + datatable( + EQ1_plot1_Data(), + style = 'bootstrap', + class = 'table-bordered table-condensed', + rownames = FALSE, + options = list( + pageLength = 16, + autoWidth = TRUE, + dom = 'tip' + ), + colnames = c( + "Financial year", + "Area Type", + "Area Name", + "Risk ratio", + "SMR04 population rate", + "General population rate" + ) + ) +}) +#Rate_Type, Year, area_type, area_name, Rate +output$EQ1_2_table <- renderDataTable({ + datatable( + EQ1_plot4_Data(), + style = 'bootstrap', + class = 'table-bordered table-condensed', + rownames = FALSE, + options = list( + pageLength = 16, + autoWidth = TRUE, + dom = 'tip' + ), + colnames = c("Rate type", + "Financial year", + "Area Type", + "Area Name", + "Rate") + ) }) - - - + + +# Create download buttons that allows users to the download tables in .csv format. +output$EQ1_1_table_download <- downloadHandler( + filename = 'EQ1_Table1.csv', + content = function(file) { + write.table( + EQ1_plot1_Data(), + file, + #Remove row numbers as the .csv file already has row numbers. + row.names = FALSE, + col.names = c( + "Financial year", + "Area Type", + "Area Name", + "Risk ratio", + "SMR04 population rate", + "General population rate" + ), + sep = "," + ) + } +) + +output$EQ1_2_table_download <- downloadHandler( + filename = 'EQ1_Table2.csv', + content = function(file) { + write.table( + EQ1_plot4_Data(), + file, + #Remove row numbers as the .csv file already has row numbers. + row.names = FALSE, + col.names = c("Rate type", + "Financial year", + "Area Type", + "Area Name", + "Rate"), + sep = "," + ) + } +) + + # Table below graph creation ---- # output$E1_1_trend_table <- renderDataTable({ @@ -222,30 +354,30 @@ output$EQ1_plot4 <- renderPlotly({ # colnames = c("Financial year", # "Area of Residence", # "Number of Bed Days")) -# }) - +# }) + # OLD CODE (keeping in case needed for reference) ---- -# -# # -# # -# # # +# +# # +# # +# # # # # # # # No data plot # # # # if(sum(E1_plot1_Data()$dd_bed_days) == 0 & # # # # !is.na(sum(E1_plot1_Data()$dd_bed_days))) -# # # # +# # # # # # # # { # # # # noDataPlot(phs_colours("phs-purple")) # # # # } -# # # # +# # # # # # # # else { -# # # +# # # # # ### 3 - Tooltip creation ---- -# # +# # # # tooltip_EQ1 <- paste0("Financial year: ", # # EQ1_plot1_Data()$Year, # # "
", @@ -254,9 +386,9 @@ output$EQ1_plot4 <- renderPlotly({ # # "
", # # "Mortality rate: ", # # EQ1_plot1_Data()$risk_ratio) -# # +# # # # ### 4 - Create the main body of the chart ---- -# # +# # # # plot_ly(data = EQ1_plot1_Data(), # # # Select your variables. # # x = ~as.factor(Year), y = ~risk_ratio, color = ~area_name, @@ -268,15 +400,15 @@ output$EQ1_plot4 <- renderPlotly({ # # linetype = ~area_name, # # linetypes = c("solid", "dot"), # # # Select symbols for the health boards, and set their size. -# # symbol = ~area_name, +# # symbol = ~area_name, # # symbols = c("circle", "triangle-up", "circle", "triangle-up"), # # marker = list(size = 12), # # name = ~str_wrap(area_name, 19)) %>% # legend labels -# # +# # # # ### 7 - Graph title ---- -# # +# # # # # Make the graph title reactive. -# # +# # # # layout(title = # # paste0( # # "", @@ -288,9 +420,9 @@ output$EQ1_plot4 <- renderPlotly({ # # "
", # # "
" # # ), -# # +# # # # separators = ".", -# # +# # # # yaxis = list( # # exponentformat = "none", # # separatethousands = TRUE, @@ -304,7 +436,7 @@ output$EQ1_plot4 <- renderPlotly({ # # showline = TRUE, # # ticks = "outside" # # ), -# # +# # # # xaxis = list( # # title = paste0(c("
", # # "Calendar year", @@ -312,7 +444,7 @@ output$EQ1_plot4 <- renderPlotly({ # # showline = TRUE, # # ticks = "outside" # # ), -# # +# # # # margin = list(l = 90, r = 60, b = 180, t = 120), # # title = list(size = 15), # # font = list(size = 13), @@ -326,22 +458,22 @@ output$EQ1_plot4 <- renderPlotly({ # # # xanchor = "center", # use center of legend as anchor # # # x = 0.5, y = -0.9) # put legend in center of x-axis # # ) %>% -# # +# # # # ### 13 - Remove unnecessary buttons from the modebar ---- -# # +# # # # config(displayModeBar = TRUE, # # modeBarButtonsToRemove = bttn_remove, # # displaylogo = F, editable = F) -# # +# # # # # } -# # +# # # # }) -# -# -# # -# # +# +# +# # +# # # # ####### Create the SMR04 rates bar chart. -# # +# # # # output$EQ1_plot2 <- renderPlotly({ # # # # # # # # No data plot @@ -355,7 +487,7 @@ output$EQ1_plot4 <- renderPlotly({ # # # # else { # # # # # ### 3 - Tooltip creation ---- -# # +# # # # tooltip_EQ1_2 <- paste0("Financial year: ", # # EQ1_plot1_Data()$Year, # # "
", @@ -364,9 +496,9 @@ output$EQ1_plot4 <- renderPlotly({ # # "
", # # "Mortality rate: ", # # EQ1_plot1_Data()$SMR04_Pop_Rate) -# # +# # # # ### 4 - Create the main body of the chart ---- -# # +# # # # plot_ly(data = EQ1_plot1_Data(), # # # Select your variables. # # x = ~Year, y = ~SMR04_Pop_Rate, type = 'bar', color = ~area_name, @@ -375,11 +507,11 @@ output$EQ1_plot4 <- renderPlotly({ # # text = tooltip_EQ1_2, hoverinfo = "text", # # marker = list(size = 12), # # name = ~str_wrap(area_name, 19)) %>% # legend labels -# # +# # # # ### 7 - Graph title ---- -# # +# # # # # Make the graph title reactive. -# # +# # # # layout(title = # # paste0( # # "", @@ -391,9 +523,9 @@ output$EQ1_plot4 <- renderPlotly({ # # "
", # # "
" # # ), -# # +# # # # separators = ".", -# # +# # # # yaxis = list( # # exponentformat = "none", # # separatethousands = TRUE, @@ -407,7 +539,7 @@ output$EQ1_plot4 <- renderPlotly({ # # showline = TRUE, # # ticks = "outside" # # ), -# # +# # # # xaxis = list( # # title = paste0(c("
", # # "Area name", @@ -415,7 +547,7 @@ output$EQ1_plot4 <- renderPlotly({ # # showline = TRUE, # # ticks = "outside" # # ), -# # +# # # # margin = list(l = 90, r = 60, b = 180, t = 120), # # title = list(size = 15), # # font = list(size = 13), @@ -429,22 +561,22 @@ output$EQ1_plot4 <- renderPlotly({ # # # xanchor = "center", # use center of legend as anchor # # # x = 0.5, y = -0.9) # put legend in center of x-axis # # ) %>% -# # +# # # # ### 13 - Remove unnecessary buttons from the modebar ---- -# # +# # # # config(displayModeBar = TRUE, # # modeBarButtonsToRemove = bttn_remove, # # displaylogo = F, editable = F) -# # +# # # # # } -# # +# # # # }) -# # -# # -# # -# # +# # +# # +# # +# # # # ####### Create the general population rates bar chart. -# # +# # # # output$EQ1_plot3 <- renderPlotly({ # # # # # # # # No data plot @@ -458,7 +590,7 @@ output$EQ1_plot4 <- renderPlotly({ # # # # else { # # # # # ### 3 - Tooltip creation ---- -# # +# # # # tooltip_EQ1_3 <- paste0("Financial year: ", # # EQ1_plot1_Data()$Year, # # "
", @@ -467,9 +599,9 @@ output$EQ1_plot4 <- renderPlotly({ # # "
", # # "Mortality rate: ", # # EQ1_plot1_Data()$General_Pop_Rate) -# # +# # # # ### 4 - Create the main body of the chart ---- -# # +# # # # plot_ly(data = EQ1_plot1_Data(), # # # Select your variables. # # x = ~Year, y = ~General_Pop_Rate, type = 'bar', color = ~area_name, @@ -478,11 +610,11 @@ output$EQ1_plot4 <- renderPlotly({ # # text = tooltip_EQ1_3, hoverinfo = "text", # # marker = list(size = 12), # # name = ~str_wrap(area_name, 19)) %>% # legend labels -# # +# # # # ### 7 - Graph title ---- -# # +# # # # # Make the graph title reactive. -# # +# # # # layout(title = # # paste0( # # "", @@ -494,9 +626,9 @@ output$EQ1_plot4 <- renderPlotly({ # # "
", # # "
" # # ), -# # +# # # # separators = ".", -# # +# # # # yaxis = list( # # exponentformat = "none", # # separatethousands = TRUE, @@ -510,7 +642,7 @@ output$EQ1_plot4 <- renderPlotly({ # # showline = TRUE, # # ticks = "outside" # # ), -# # +# # # # xaxis = list( # # title = paste0(c("
", # # "Area name", @@ -518,7 +650,7 @@ output$EQ1_plot4 <- renderPlotly({ # # showline = TRUE, # # ticks = "outside" # # ), -# # +# # # # margin = list(l = 90, r = 60, b = 180, t = 120), # # title = list(size = 15), # # font = list(size = 13), @@ -532,22 +664,22 @@ output$EQ1_plot4 <- renderPlotly({ # # # xanchor = "center", # use center of legend as anchor # # # x = 0.5, y = -0.9) # put legend in center of x-axis # # ) %>% -# # +# # # # ### 13 - Remove unnecessary buttons from the modebar ---- -# # +# # # # config(displayModeBar = TRUE, # # modeBarButtonsToRemove = bttn_remove, # # displaylogo = F, editable = F) -# # +# # # # # } -# # +# # # # }) -# # -# # -# -# -# -# +# # +# # +# +# +# +# # output$EQ1_plot4_areaType_output <- renderUI({ # shinyWidgets::pickerInput( # "EQ1_plot4_areaType", @@ -555,7 +687,7 @@ output$EQ1_plot4 <- renderPlotly({ # choices = unique_area_types, # selected = "Health board") # }) -# +# # output$EQ1_plot4_areaName_output <- renderUI({ # shinyWidgets::pickerInput( # "EQ1_plot4_areaName", @@ -570,16 +702,16 @@ output$EQ1_plot4 <- renderPlotly({ # `selected-text-format` = "count > 1") # ) # }) -# -# +# +# # EQ1_plot4_Data <- reactive({ # EQ1_reformatted_data %>% # select(Rate_Type, Year, area_type, area_name, Rate) %>% # filter(area_type %in% input$EQ1_plot4_areaType # & area_name %in% input$EQ1_plot4_areaName) # }) -# -# +# +# # ####### Create the combined general population and MH rates bar chart. # # # output$EQ1_plot4 <- renderPlotly({ @@ -595,7 +727,7 @@ output$EQ1_plot4 <- renderPlotly({ # # # else { # # # ### 3 - Tooltip creation ---- -# +# # tooltip_EQ1_4 <- paste0("Financial year: ", # EQ1_plot4_Data()$Year, # "
", @@ -607,9 +739,9 @@ output$EQ1_plot4 <- renderPlotly({ # "
", # "Rate: ", # EQ1_plot4_Data()$Rate) -# +# # ### 4 - Create the main body of the chart ---- -# +# # plot_ly(data = EQ1_plot4_Data(), # # Select your variables. # x = ~Year, y = ~Rate, type = 'bar', color = ~Rate_Type, @@ -618,11 +750,11 @@ output$EQ1_plot4 <- renderPlotly({ # text = tooltip_EQ1_4, hoverinfo = "text", # marker = list(size = 12), # name = ~str_wrap(Rate_Type, 19)) %>% # legend labels -# +# # ### 7 - Graph title ---- -# +# # # Make the graph title reactive. -# +# # layout(title = # paste0( # "", @@ -634,9 +766,9 @@ output$EQ1_plot4 <- renderPlotly({ # "
", # "
" # ), -# +# # separators = ".", -# +# # yaxis = list( # exponentformat = "none", # separatethousands = TRUE, @@ -650,7 +782,7 @@ output$EQ1_plot4 <- renderPlotly({ # showline = TRUE, # ticks = "outside" # ), -# +# # xaxis = list( # title = paste0(c("
", # "Area name", @@ -658,7 +790,7 @@ output$EQ1_plot4 <- renderPlotly({ # showline = TRUE, # ticks = "outside" # ), -# +# # margin = list(l = 90, r = 60, b = 180, t = 120), # title = list(size = 15), # font = list(size = 13), @@ -672,20 +804,20 @@ output$EQ1_plot4 <- renderPlotly({ # # xanchor = "center", # use center of legend as anchor # # x = 0.5, y = -0.9) # put legend in center of x-axis # ) %>% -# +# # ### 13 - Remove unnecessary buttons from the modebar ---- -# +# # config(displayModeBar = TRUE, # modeBarButtonsToRemove = bttn_remove, # displaylogo = F, editable = F) -# +# # # } -# +# # }) -# -# +# +# # ### 15 - Table below graph creation ---- -# +# # # output$E1_1_trend_table <- renderDataTable({ # # datatable(E1_plot1_Data(), # # style = 'bootstrap', @@ -696,13 +828,4 @@ output$EQ1_plot4 <- renderPlotly({ # # "Area of Residence", # # "Number of Bed Days")) # # }) -# - - - - - - - - - +# diff --git a/modules/indicators/EQ1_ui.R b/modules/indicators/EQ1_ui.R index ac6ab14..89d0512 100644 --- a/modules/indicators/EQ1_ui.R +++ b/modules/indicators/EQ1_ui.R @@ -4,22 +4,22 @@ tabItem(tabName = "EQ1_tab", fluidPage( h1("EQ1 - Premature mortality rate = Standardised mortality rate ", "for persons in contact with mental health services"), - + hr(), # page break - # First Graph ---- + # First Graph ---- # Text above graph fluidRow( - column(12, - box(width = NULL, - p("Below is a graph showing the changes over time of the ", - "mortality rates for persons in contact with mental health ", - "services. ", - br(), - "This is broken down by either council area or health board of ", - "residence. Please use the drop down menus to select which ", - "areas you wish to look at."))) + column(12, + box(width = NULL, + p("Below is a graph showing the changes over time of the ", + "mortality rates for persons in contact with mental health ", + "services. ", + br(), + "This is broken down by either council area or health board of ", + "residence. Please use the drop down menus to select which ", + "areas you wish to look at."))) ), # Geography Drop Down Menus @@ -39,154 +39,192 @@ tabItem(tabName = "EQ1_tab", box(width = 12, phs_spinner("EQ1_plot1")) ), + hr(), # page break + fluidRow( + box(title = "This section can be expanded to view the data in the graph above as a table.", + width = 12, solidHeader = TRUE, collapsible = TRUE, collapsed = TRUE, + dataTableOutput("EQ1_1_table") + ) + ), + fluidRow( + column(4, + downloadButton(outputId = "EQ1_1_table_download", + label = "Download as .csv", + class = "EQ1_1_table_downloadbutton"), + tags$head( + tags$style(".EQ1_1_table_downloadbutton { background-color: + #3F3685; } + .EQ1_1_table_downloadbutton { color: #FFFFFF; }") + ) + ) + ), hr(), # page break - # Second graph ---- + # Second graph ---- # Text above graph fluidRow( - column(12, - box(width = NULL, - p("Below is a graph showing the changes over time of the ", - "mortality rates for the general population and the mental ", - "health population for your chosen area.", - br(), - "This is broken down by either council area or health board of ", - "residence. Please use the drop down menus to select which ", - "area you wish to look at."))) + column(12, + box(width = NULL, + p("Below is a graph showing the changes over time of the ", + "mortality rates for the general population and the mental ", + "health population for your chosen area.", + br(), + "This is broken down by either council area or health board of ", + "residence. Please use the drop down menus to select which ", + "area you wish to look at."))) ), # Geography Drop Down Menus - fluidRow( - column(6, - box(width = NULL, - uiOutput("EQ1_plot4_areaType_output"))), - column(6, - box(width = NULL, - uiOutput("EQ1_plot4_areaName_output"))), + fluidRow( + column(6, + box(width = NULL, + uiOutput("EQ1_plot4_areaType_output"))), + column(6, + box(width = NULL, + uiOutput("EQ1_plot4_areaName_output"))), ), - - # Graph 2 output - fluidRow( - box(width = 12, - phs_spinner("EQ1_plot4")) + + # Graph 2 output + fluidRow( + box(width = 12, + phs_spinner("EQ1_plot4")) ), - - br(), - - # Navigation Buttons ---- - go_2_top_bttn, - - br(), - - fluidRow( - column(4, actionButton(inputId = "EQ1_scot_hub_button", - label = "Scotland Hub", icon = icon("home"), - class = "navpageButton")), - column(4, actionButton(inputId = "EF5_prevButton", - label = "Previous Page", icon = icon("arrow-left"), - class = "navpageButton")), - column(4, actionButton(inputId = "EQ2_nextButton", - label = "Next Page", icon = icon("arrow-right"), - class = "navpageButton")) - ) - - - - + hr(), # page break + + fluidRow( + box(title = "This section can be expanded to view the data in the graph above as a table.", + width = 12, solidHeader = TRUE, collapsible = TRUE, collapsed = TRUE, + dataTableOutput("EQ1_2_table") + ) + ), + fluidRow( + column(4, + downloadButton(outputId = "EQ1_2_table_download", + label = "Download as .csv", + class = "EQ1_2_table_downloadbutton"), + tags$head( + tags$style(".EQ1_2_table_downloadbutton { background-color: + #3F3685; } + .EQ1_2_table_downloadbutton { color: #FFFFFF; }") + ) + ) + ), + br(), + + # Navigation Buttons ---- + go_2_top_bttn, + + br(), + + fluidRow( + column(4, actionButton(inputId = "EQ1_scot_hub_button", + label = "Scotland Hub", icon = icon("home"), + class = "navpageButton")), + column(4, actionButton(inputId = "EF5_prevButton", + label = "Previous Page", icon = icon("arrow-left"), + class = "navpageButton")), + column(4, actionButton(inputId = "EQ2_nextButton", + label = "Next Page", icon = icon("arrow-right"), + class = "navpageButton")) + ) + + + + ), # End of fluidPage ) - - - # titlePanel(paste0( - # "EQ1 - Premature mortality rate = Standardised mortality rate ", - # "for persons in contact with mental health services")), - - - - - - # mainPanel( - # tags$p("Below is a graph showing the changes over time."), - # - # fluidRow( - # column(6,uiOutput("EQ1_plot1_areaType_output")), - # column(6,uiOutput("EQ1_plot1_areaName_output")) - # ), - # - # fluidRow( - # plotlyOutput("EQ1_plot1" - # # , - # # width = "100%", - # # height = "50%" - # ) - # ), - # - # br(), - # # br(), - # # fluidRow( - # # plotlyOutput("EQ1_plot2" - # # # , - # # # width = "100%", - # # # height = "50%" - # # ) - # # ), - # # br(), - # # br(), - # # fluidRow( - # # plotlyOutput("EQ1_plot3" - # # # , - # # # width = "100%", - # # # height = "50%" - # # ) - # # ), - # # br(), - # fluidRow( - # column(6,uiOutput("EQ1_plot4_areaType_output")), - # column(6,uiOutput("EQ1_plot4_areaName_output")) - # ), - # br(), - # fluidRow( - # plotlyOutput("EQ1_plot4" - # # , - # # width = "100%", - # # height = "50%" - # ) - # ), - # br(), - # - # - # - # br(), - # - # go_2_top_bttn, - # - # # tags$a(href = '#E1_top', - # # icon("circle-arrow-up", - # # lib = "glyphicon"), - # # "Back to top"), - # br(), - # br(), - # # ), # End of mainPanel - # - # - # - # - # - # fluidRow( - # column(4, actionButton(inputId = "EQ1_scot_hub_button", - # label = "Scotland Hub", icon = icon("home"), - # class = "navpageButton")), - # column(4, actionButton(inputId = "EF5_prevButton", - # label = "Previous Page", icon = icon("arrow-left"), - # class = "navpageButton")), - # column(4, actionButton(inputId = "EQ2_nextButton", - # label = "Next Page", icon = icon("arrow-right"), - # class = "navpageButton")) - # ) - # ) # End of mainPanel - # ) # End of fluidPage - # ) - # + + +# titlePanel(paste0( +# "EQ1 - Premature mortality rate = Standardised mortality rate ", +# "for persons in contact with mental health services")), + + + + + +# mainPanel( +# tags$p("Below is a graph showing the changes over time."), +# +# fluidRow( +# column(6,uiOutput("EQ1_plot1_areaType_output")), +# column(6,uiOutput("EQ1_plot1_areaName_output")) +# ), +# +# fluidRow( +# plotlyOutput("EQ1_plot1" +# # , +# # width = "100%", +# # height = "50%" +# ) +# ), +# +# br(), +# # br(), +# # fluidRow( +# # plotlyOutput("EQ1_plot2" +# # # , +# # # width = "100%", +# # # height = "50%" +# # ) +# # ), +# # br(), +# # br(), +# # fluidRow( +# # plotlyOutput("EQ1_plot3" +# # # , +# # # width = "100%", +# # # height = "50%" +# # ) +# # ), +# # br(), +# fluidRow( +# column(6,uiOutput("EQ1_plot4_areaType_output")), +# column(6,uiOutput("EQ1_plot4_areaName_output")) +# ), +# br(), +# fluidRow( +# plotlyOutput("EQ1_plot4" +# # , +# # width = "100%", +# # height = "50%" +# ) +# ), +# br(), +# +# +# +# br(), +# +# go_2_top_bttn, +# +# # tags$a(href = '#E1_top', +# # icon("circle-arrow-up", +# # lib = "glyphicon"), +# # "Back to top"), +# br(), +# br(), +# # ), # End of mainPanel +# +# +# +# +# +# fluidRow( +# column(4, actionButton(inputId = "EQ1_scot_hub_button", +# label = "Scotland Hub", icon = icon("home"), +# class = "navpageButton")), +# column(4, actionButton(inputId = "EF5_prevButton", +# label = "Previous Page", icon = icon("arrow-left"), +# class = "navpageButton")), +# column(4, actionButton(inputId = "EQ2_nextButton", +# label = "Next Page", icon = icon("arrow-right"), +# class = "navpageButton")) +# ) +# ) # End of mainPanel +# ) # End of fluidPage +# ) +# From d5d5a4500831818d2c03d6dafc764b4082497fed Mon Sep 17 00:00:00 2001 From: Cormac-Murray Date: Thu, 3 Oct 2024 14:06:37 +0100 Subject: [PATCH 69/75] Set the collapsable tables to be uncollapsed at load. --- modules/indicators/E1_ui.R | 4 ++-- modules/indicators/EF4_ui.R | 2 +- modules/indicators/EQ1_ui.R | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/indicators/E1_ui.R b/modules/indicators/E1_ui.R index bc75e10..cb9ba1e 100644 --- a/modules/indicators/E1_ui.R +++ b/modules/indicators/E1_ui.R @@ -67,7 +67,7 @@ tabItem(tabName = "E1_tab", # Table with graph 1 data fluidRow( box(title = "This section can be expanded to view the data in the graph above as a table.", - width = 12, solidHeader = TRUE, collapsible = TRUE, collapsed = TRUE, + width = 12, solidHeader = TRUE, collapsible = TRUE, collapsed = FALSE, dataTableOutput("E1_1_table") ) ), @@ -133,7 +133,7 @@ tabItem(tabName = "E1_tab", # Table with graph 2 data fluidRow( box(title = "This section can be expanded to view the data in the graph above as a table.", - width = 12, solidHeader = TRUE, collapsible = TRUE, collapsed = TRUE, + width = 12, solidHeader = TRUE, collapsible = TRUE, collapsed = FALSE, dataTableOutput("E1_2_table") ) ), diff --git a/modules/indicators/EF4_ui.R b/modules/indicators/EF4_ui.R index 1cb01dc..1669a26 100644 --- a/modules/indicators/EF4_ui.R +++ b/modules/indicators/EF4_ui.R @@ -40,7 +40,7 @@ tabItem(tabName = "EF4_tab", fluidRow( box(title = "This section can be expanded to view the data in the graph above as a table.", - width = 12, solidHeader = TRUE, collapsible = TRUE, collapsed = TRUE, + width = 12, solidHeader = TRUE, collapsible = TRUE, collapsed = FALSE, dataTableOutput("EF4_table") ) ), diff --git a/modules/indicators/EQ1_ui.R b/modules/indicators/EQ1_ui.R index 89d0512..58b1600 100644 --- a/modules/indicators/EQ1_ui.R +++ b/modules/indicators/EQ1_ui.R @@ -43,7 +43,7 @@ tabItem(tabName = "EQ1_tab", fluidRow( box(title = "This section can be expanded to view the data in the graph above as a table.", - width = 12, solidHeader = TRUE, collapsible = TRUE, collapsed = TRUE, + width = 12, solidHeader = TRUE, collapsible = TRUE, collapsed = FALSE, dataTableOutput("EQ1_1_table") ) ), @@ -96,7 +96,7 @@ tabItem(tabName = "EQ1_tab", fluidRow( box(title = "This section can be expanded to view the data in the graph above as a table.", - width = 12, solidHeader = TRUE, collapsible = TRUE, collapsed = TRUE, + width = 12, solidHeader = TRUE, collapsible = TRUE, collapsed = FALSE, dataTableOutput("EQ1_2_table") ) ), From 57c636d6dca91eeb0e7710990424347167d71f19 Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Mon, 7 Oct 2024 12:37:56 +0100 Subject: [PATCH 70/75] Updated password protection --- app.R | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app.R b/app.R index 1d5cd8c..4f52804 100644 --- a/app.R +++ b/app.R @@ -15,6 +15,7 @@ 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 ---------------------------------------------------- @@ -28,13 +29,15 @@ 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 +credentials <- readRDS("admin/credentials.rds") # Un-comment if password protection needed ### [ UI section ] ------------------------------------------------------------- -# secure_app( # Un-comment if password protection is needed. -ui <- dashboardPage( + +ui <- + secure_app( # Un-comment if password protection is needed. + dashboardPage( dashboardHeader(title = "MH Quality Indicators"), @@ -96,8 +99,9 @@ ui <- dashboardPage( ) # End of tabItems ) # End of dashboardBody -) # End of UI -# ) # End of password-protection wrapper +) # End of dashboardPage +) # End of password-protection wrapper + ### [ Server ] ----------------------------------------------------------------- @@ -106,13 +110,13 @@ 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) - # }) + 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) From 8cc1e98204169725a5d964df7a0ef23576a41d52 Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Mon, 7 Oct 2024 12:38:34 +0100 Subject: [PATCH 71/75] Updated password protection --- app.R | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app.R b/app.R index 4f52804..60b2666 100644 --- a/app.R +++ b/app.R @@ -29,14 +29,14 @@ 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 +# credentials <- readRDS("admin/credentials.rds") # Un-comment if password protection needed ### [ UI section ] ------------------------------------------------------------- ui <- - secure_app( # Un-comment if password protection is needed. + # secure_app( # Un-comment if password protection is needed. dashboardPage( dashboardHeader(title = "MH Quality Indicators"), @@ -100,7 +100,7 @@ ui <- ) # End of tabItems ) # End of dashboardBody ) # End of dashboardPage -) # End of password-protection wrapper +# ) # End of password-protection wrapper @@ -110,13 +110,13 @@ 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) - }) + # 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) From 6182306b57bedfb16b38e24767cee1075c0d9fe8 Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Mon, 7 Oct 2024 12:53:54 +0100 Subject: [PATCH 72/75] Updated .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index b559259..c38a0d4 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,8 @@ .Rproj.user/ *.Rproj +# Folder readme +FOLDER_INFO.txt # Deployment secrets # Credentials script From b5bfbd308e6de7e8716e6609005d5ede88c364a3 Mon Sep 17 00:00:00 2001 From: alex-bruce Date: Mon, 7 Oct 2024 15:56:57 +0100 Subject: [PATCH 73/75] Minor Scot Hub fixes --- modules/scot_hub_ui.R | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/modules/scot_hub_ui.R b/modules/scot_hub_ui.R index 50d82fb..c611ce2 100644 --- a/modules/scot_hub_ui.R +++ b/modules/scot_hub_ui.R @@ -45,8 +45,9 @@ tabItem(tabName = "scot_hub", # Header Text title = tagList(icon("hourglass-end"), paste0( - "T3 - % of people who commence psychological therapy ", - "based treatment within 18 weeks of referral ", + "T3 - % of people who wait less than three weeks ", + "from referral received to appropriate drug or ", + "alcohol treatment that supports their recovery ", T3_dateText,":")), width = 4, solidHeader = TRUE, # Body text @@ -171,7 +172,7 @@ tabItem(tabName = "scot_hub", box(## P4 ---- # Header Text title = tagList( - icon("hourglass-end"), + icon("clipboard"), paste0("P4 - number of people with Advance Statements ", "registered in ", P4_dateText,":")), width = 4, solidHeader = TRUE, @@ -192,15 +193,19 @@ tabItem(tabName = "scot_hub", fluidRow( box(## E1 ---- - # Link in title instead of button - title = actionLink("E1_button", - "E1 - Days in hospital when clinically - ready to discharge, per 1,000 population:", - icon = icon("refresh")), + title = tagList( + icon("hourglass-end"), + paste0("E1 - Days in hospital when clinically + ready to discharge, per 1,000 population:")), width = 4, solidHeader = TRUE, - paste0(E1)) + # Body text + paste0(E1), + # Navigation button + actionButton(inputId = "E1_button", + label = "E1 - Find out more", + class = "navpageButton pull-right") - ), + )), br(), @@ -212,7 +217,7 @@ tabItem(tabName = "scot_hub", box(## EF1 ---- # Header Text title = tagList( - icon("hourglass-end"), + icon("bed"), "EF1 - Rate of Emergency Bed Days for Adults:"), width = 4, solidHeader = TRUE, # Body text @@ -226,7 +231,7 @@ tabItem(tabName = "scot_hub", box(## EF2 ---- # Header Text title = tagList( - icon("hourglass-end"), + icon("refresh"), paste0("EF2 - % of Readmissions to hospital within 28 Days of Discharge:") ), width = 4, solidHeader = TRUE, @@ -242,7 +247,7 @@ tabItem(tabName = "scot_hub", box( # Header Text title = tagList( - icon("hourglass-end"), + icon("bed"), paste0("EF3 - Total Psychiatric Inpatient Beds per 100,000 population:") ), width = 4, solidHeader = TRUE, @@ -257,7 +262,7 @@ tabItem(tabName = "scot_hub", box(# EF4 ---- # Header Text title = tagList( - icon("hourglass-end"), + icon("sterling-sign"), paste0("EF4 - Total Mental Health Spend as a % of Total Spend:")), width = 4, solidHeader = TRUE, # Body text @@ -309,7 +314,7 @@ tabItem(tabName = "scot_hub", box(## EQ2 ---- # Header Text - title = tagList(icon("hourglass-end"), + title = tagList(icon("clipboard"), paste0("EQ2 - Number of Emergency Detention Certificates ", "per 100,000 population (2020/21):")), width = 4, solidHeader = TRUE, @@ -340,7 +345,7 @@ tabItem(tabName = "scot_hub", box(## EQ4 ---- # Header Text - title = tagList(icon("hourglass-end"), + title = tagList(icon("child"), paste0( "EQ4 - % of under 18 psychiatric admissions ", "admitted outwith specialist CAMH wards (Sep 2020 - Sep 2021):")), From f4a8b410a4ccc91e04af694565ea8789015b6e8c Mon Sep 17 00:00:00 2001 From: Cormac-Murray Date: Mon, 7 Oct 2024 15:59:10 +0100 Subject: [PATCH 74/75] Update table headers and give downloadable csv files more descriptive names --- modules/indicators/E1_server.R | 4 ++-- modules/indicators/E1_ui.R | 6 ++++-- modules/indicators/EF4_server.R | 2 +- modules/indicators/EF4_ui.R | 3 ++- modules/indicators/EQ1_server.R | 4 ++-- modules/indicators/EQ1_ui.R | 6 ++++-- 6 files changed, 15 insertions(+), 10 deletions(-) diff --git a/modules/indicators/E1_server.R b/modules/indicators/E1_server.R index d9e4fbd..fcec46b 100644 --- a/modules/indicators/E1_server.R +++ b/modules/indicators/E1_server.R @@ -378,7 +378,7 @@ output$E1_2_table <- renderDataTable({ # Create download buttons that allows users to the download tables in .csv format. output$E1_1_table_download <- downloadHandler( - filename = 'E1_Table1.csv', + filename = 'E1 - Total bed days for chosen area.csv', content = function(file) { write.table(E1_plot1_Data(), file, @@ -393,7 +393,7 @@ output$E1_1_table_download <- downloadHandler( ) output$E1_2_table_download <- downloadHandler( - filename = 'E1_Table2.csv', + filename = 'E1 - Total bed days for chosen year.csv', content = function(file) { write.table(E1_plot2_Data_download(), file, diff --git a/modules/indicators/E1_ui.R b/modules/indicators/E1_ui.R index cb9ba1e..a21c98c 100644 --- a/modules/indicators/E1_ui.R +++ b/modules/indicators/E1_ui.R @@ -66,7 +66,8 @@ tabItem(tabName = "E1_tab", # ), # End of fluidRow # Table with graph 1 data fluidRow( - box(title = "This section can be expanded to view the data in the graph above as a table.", + box(title = "Below is a table showing the data used to create the above graph. + It can be downloaded using the 'Download as .csv' button underneath this section", width = 12, solidHeader = TRUE, collapsible = TRUE, collapsed = FALSE, dataTableOutput("E1_1_table") ) @@ -132,7 +133,8 @@ tabItem(tabName = "E1_tab", # ), # End of fluidRow # Table with graph 2 data fluidRow( - box(title = "This section can be expanded to view the data in the graph above as a table.", + box(title = "Below is a table showing the data used to create the above graph. + It can be downloaded using the 'Download as .csv' button underneath this section", width = 12, solidHeader = TRUE, collapsible = TRUE, collapsed = FALSE, dataTableOutput("E1_2_table") ) diff --git a/modules/indicators/EF4_server.R b/modules/indicators/EF4_server.R index a32875d..9ee718c 100644 --- a/modules/indicators/EF4_server.R +++ b/modules/indicators/EF4_server.R @@ -116,7 +116,7 @@ EF4_trendPlot_data <- reactive({ # Create download button that allows users to download tables in .csv format. output$EF4_table_download <- downloadHandler( - filename = 'EF4_Table1.csv', + filename = 'EF4 - Mental health spend.csv', content = function(file) { write.table(EF4_trendPlot_data(), file, diff --git a/modules/indicators/EF4_ui.R b/modules/indicators/EF4_ui.R index 1669a26..4f1dff4 100644 --- a/modules/indicators/EF4_ui.R +++ b/modules/indicators/EF4_ui.R @@ -39,7 +39,8 @@ tabItem(tabName = "EF4_tab", hr(), # page break fluidRow( - box(title = "This section can be expanded to view the data in the graph above as a table.", + box(title = "Below is a table showing the data used to create the above graph. + It can be downloaded using the 'Download as .csv' button underneath this section", width = 12, solidHeader = TRUE, collapsible = TRUE, collapsed = FALSE, dataTableOutput("EF4_table") ) diff --git a/modules/indicators/EQ1_server.R b/modules/indicators/EQ1_server.R index 86e645e..389572e 100644 --- a/modules/indicators/EQ1_server.R +++ b/modules/indicators/EQ1_server.R @@ -304,7 +304,7 @@ output$EQ1_2_table <- renderDataTable({ # Create download buttons that allows users to the download tables in .csv format. output$EQ1_1_table_download <- downloadHandler( - filename = 'EQ1_Table1.csv', + filename = 'EQ1 - Mortality rate risk ratio trends.csv', content = function(file) { write.table( EQ1_plot1_Data(), @@ -325,7 +325,7 @@ output$EQ1_1_table_download <- downloadHandler( ) output$EQ1_2_table_download <- downloadHandler( - filename = 'EQ1_Table2.csv', + filename = paste0("EQ1 - Mortality rate trend for chosen area.csv"), content = function(file) { write.table( EQ1_plot4_Data(), diff --git a/modules/indicators/EQ1_ui.R b/modules/indicators/EQ1_ui.R index 58b1600..6746f37 100644 --- a/modules/indicators/EQ1_ui.R +++ b/modules/indicators/EQ1_ui.R @@ -42,7 +42,8 @@ tabItem(tabName = "EQ1_tab", hr(), # page break fluidRow( - box(title = "This section can be expanded to view the data in the graph above as a table.", + box(title = "Below is a table showing the data used to create the above graph. + It can be downloaded using the 'Download as .csv' button underneath this section", width = 12, solidHeader = TRUE, collapsible = TRUE, collapsed = FALSE, dataTableOutput("EQ1_1_table") ) @@ -95,7 +96,8 @@ tabItem(tabName = "EQ1_tab", hr(), # page break fluidRow( - box(title = "This section can be expanded to view the data in the graph above as a table.", + box(title = "Below is a table showing the data used to create the above graph. + It can be downloaded using the 'Download as .csv' button underneath this section", width = 12, solidHeader = TRUE, collapsible = TRUE, collapsed = FALSE, dataTableOutput("EQ1_2_table") ) From 18c7f22000e024ef8e183e0b34b059b6ce6ace40 Mon Sep 17 00:00:00 2001 From: MahriScot Date: Wed, 16 Oct 2024 16:56:27 +0100 Subject: [PATCH 75/75] Scotland Hub wording and variable values changed and linked to alt text csv file. (Some are still to be worked on) --- indicator_alt_text.R | 10 +- modules/scot_hub_ui.R | 98 +++++++------ scot_hub_data.R | 311 ++++++++++++++++++++++++++++++++++++------ 3 files changed, 332 insertions(+), 87 deletions(-) diff --git a/indicator_alt_text.R b/indicator_alt_text.R index e5baf0b..f726584 100644 --- a/indicator_alt_text.R +++ b/indicator_alt_text.R @@ -2,8 +2,8 @@ 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)) \ No newline at end of file +EF1_rate <- EF1$rate %>% + filter(fyear = max_year) + +EF1_lag_rate <- EF1$rate %>% + filter(fyear = (max_year-1)) \ No newline at end of file diff --git a/modules/scot_hub_ui.R b/modules/scot_hub_ui.R index c611ce2..e3f105f 100644 --- a/modules/scot_hub_ui.R +++ b/modules/scot_hub_ui.R @@ -13,10 +13,10 @@ tabItem(tabName = "scot_hub", paste0( "T1 - % of people who commence psychological ", "therapy based treatment within 18 weeks of referral ", - T1_dateText,":")), + T1_ScotlandHub_dateText, ":")), width = 4, solidHeader = TRUE, # Body text - paste0(T1,"%"), + paste0(T1_ScotlandHub_value,"%"), # Navigation button actionButton(inputId = "T1_button", label = "T1 - Find out more", @@ -28,14 +28,14 @@ tabItem(tabName = "scot_hub", # Header Text title = tagList(icon("hourglass-end"), paste0( - "% of young people who commence treatment by ", + "T2 - % of young people who commence treatment by ", "specialist Child and Adolescent Mental Health ", "services within 18 weeks of referral ", - T2_dateText,":")), + T2_ScotlandHub_dateText,":")), width = 4, solidHeader = TRUE, # Body text - paste0(T2,"%"), - # Navigation button + paste0(T2_ScotlandHub_value,"%"), + # Navigation button actionButton(inputId = "T2_button", label = "T2 - Find out more", class = "navpageButton pull-right") @@ -48,10 +48,10 @@ tabItem(tabName = "scot_hub", "T3 - % of people who wait less than three weeks ", "from referral received to appropriate drug or ", "alcohol treatment that supports their recovery ", - T3_dateText,":")), + T3_ScotlandHub_dateText,":")), width = 4, solidHeader = TRUE, # Body text - paste0(T3,"%"), + paste0(T3_ScotlandHub_value,"%"), # Navigation button actionButton(inputId = "T3_button", label = "T3 - Find out more", @@ -71,10 +71,10 @@ tabItem(tabName = "scot_hub", title = tagList(icon("hourglass-end"), paste0( "S1 - Suicide rates per 100,000 population ", - S1_dateText,":")), + S1_ScotlandHub_dateText,":")), width = 4, solidHeader = TRUE, # Body text - paste0(S1), + paste0(S1_ScotlandHub_value), # Navigation button actionButton(inputId = "S1_button", label = "S1 - Find out more", @@ -86,10 +86,10 @@ tabItem(tabName = "scot_hub", title = tagList(icon("hourglass-end"), paste0("S2 - % of all Discharged Psychiatric Inpatients ", "followed-up by Community Mental Health Services ", - "within 7 Calendar Days ", S2_dateText,":")), + "within 7 Calendar Days ", S2_ScotlandHub_dateText,":")), width = 4, solidHeader = TRUE, # Body text - paste0(S2_low,"% to ",S2_high,"%"), + paste0(S2_ScotlandHub_value_low,"% to ", S2_ScotlandHub_value_high,"%"), # Navigation button actionButton(inputId = "S2_button", label = "S2 - Find out more", @@ -102,10 +102,10 @@ tabItem(tabName = "scot_hub", paste0( "S5 - incidents of Physical Violence per ", "1,000 occupied Psychiatric Bed Days ", - S5_dateText,":")), + S5_ScotlandHub_dateText,":")), width = 4, solidHeader = TRUE, # Body text - paste0(S5_low," to ",S5_high), + paste0(S5_ScotlandHub_value_low," to ",S2_ScotlandHub_value_high), # Navigation button actionButton(inputId = "S5_button", label = "S5 - Find out more", @@ -124,11 +124,13 @@ tabItem(tabName = "scot_hub", # Header Text title = tagList(icon("hourglass-end"), paste0( - "P1 - Suicide rates per 100,000 population ", - P1_dateText,":")), + "P1 - % of carers with a mental health condition that felt ", + "supported to continue in their caring role ", + P1_ScotlandHub_dateText,":")), + width = 4, solidHeader = TRUE, # Body text - paste0(P1,"%"), + paste0(P1_ScotlandHub_value), # Navigation button actionButton(inputId = "P1_button", label = "P1 - Find out more", @@ -142,10 +144,10 @@ tabItem(tabName = "scot_hub", paste0( "P2 - % of Adults with MH Problems supported at home who agree ", "their support had an impact on improving or maintaining their ", - "quality of life ", P2_dateText,":")), + "quality of life ", P2_ScotlandHub_dateText,":")), width = 4, solidHeader = TRUE, # Body text - paste0(P2,"%"), + paste0(P2_ScotlandHub_value), # Navigation button actionButton(inputId = "P2_button", label = "P2 - Find out more", @@ -159,10 +161,10 @@ tabItem(tabName = "scot_hub", paste0( 'P3 - % of people with a mental health problem that agree ', 'with the statement "people took account of the things ', - 'that mattered to me" ', P3_dateText,":")), + 'that mattered to me" ', P3_ScotlandHub_dateText,":")), width = 4, solidHeader = TRUE, # Body text - paste0(P3,"%"), + paste0(P3_ScotlandHub_value), # Navigation button actionButton(inputId = "P3_button", label = "P3 - Find out more", @@ -174,10 +176,11 @@ tabItem(tabName = "scot_hub", title = tagList( icon("clipboard"), paste0("P4 - number of people with Advance Statements ", - "registered in ", P4_dateText,":")), + "registered with the Mental Welfare Commission for Scotland ", + P4_ScotlandHub_dateText,":")), width = 4, solidHeader = TRUE, # Body text - paste0(P4), + paste0(P4_ScotlandHub_value), # Navigation button actionButton(inputId = "P4_button", label = "P4 - Find out more", @@ -196,10 +199,11 @@ tabItem(tabName = "scot_hub", title = tagList( icon("hourglass-end"), paste0("E1 - Days in hospital when clinically - ready to discharge, per 1,000 population:")), + ready to discharge, per 1,000 population ", + E1_ScotlandHub_dateText, ":")), width = 4, solidHeader = TRUE, # Body text - paste0(E1), + paste0(E1_ScotlandHub_value), # Navigation button actionButton(inputId = "E1_button", label = "E1 - Find out more", @@ -218,10 +222,11 @@ tabItem(tabName = "scot_hub", # Header Text title = tagList( icon("bed"), - "EF1 - Rate of Emergency Bed Days for Adults:"), + "EF1 - Rate of Emergency Bed Days for Adults per 100,000 population ", + EF1_ScotlandHub_dateText, ":"), width = 4, solidHeader = TRUE, # Body text - paste0(EF1," / 100,000"), + paste0(EF1_ScotlandHub_value), # Navigation button actionButton(inputId = "EF1_button", label = "EF1 - Find out more", @@ -232,11 +237,12 @@ tabItem(tabName = "scot_hub", # Header Text title = tagList( icon("refresh"), - paste0("EF2 - % of Readmissions to hospital within 28 Days of Discharge:") + paste0("EF2 - % of Readmissions to hospital within 28 Days of Discharge ", + EF2_ScotlandHub_dateText, ":") ), width = 4, solidHeader = TRUE, # Body text - paste0(EF2,"%"), + paste0(EF2_ScotlandHub_value, "%"), # Navigation button actionButton(inputId = "EF2_button", label = "EF2 - Find out more", @@ -248,11 +254,12 @@ tabItem(tabName = "scot_hub", # Header Text title = tagList( icon("bed"), - paste0("EF3 - Total Psychiatric Inpatient Beds per 100,000 population:") + paste0("EF3 - Total Psychiatric Inpatient Beds per 100,000 population ", + EF3_ScotlandHub_dateText, ":") ), width = 4, solidHeader = TRUE, # Body text - paste0(EF3), + paste0(EF3_ScotlandHub_value), # Navigation button actionButton(inputId = "EF3_button", label = "EF3 - Find out more", @@ -263,10 +270,11 @@ tabItem(tabName = "scot_hub", # Header Text title = tagList( icon("sterling-sign"), - paste0("EF4 - Total Mental Health Spend as a % of Total Spend:")), + paste0("EF4 - Total Mental Health Spend as a % of Total Spend ", + EF4_ScotlandHub_dateText, ":")), width = 4, solidHeader = TRUE, # Body text - paste0(EF4,"% ", EF4_text), + paste0(EF4_ScotlandHub_value, "%"), # Navigation button actionButton(inputId = "EF4_button", label = "EF4 - Find out more", @@ -277,11 +285,12 @@ tabItem(tabName = "scot_hub", # Header Text title = tagList(icon("hourglass-end"), paste0("EF5 - % of Did Not Attend Appointments for ", - "Community based services (Mental Health October - December 2021):") + "Community based services (Mental Health ", + EF5_ScotlandHub_dateText, "):") ), width = 4, solidHeader = TRUE, # Body text - paste0(EF5_low,"% - ",EF5_high, "%"), + paste0(EF5_ScotlandHub_value_low,"% - ",EF5_ScotlandHub_value_high, "%"), # Navigation button actionButton(inputId = "EF5_button", label = "EF5 - Find out more", @@ -301,10 +310,11 @@ tabItem(tabName = "scot_hub", # Header Text title = tagList(icon("hourglass-end"), paste0("EQ1 - Premature Mortality rate for Persons ", - "in contact with Mental Health Services (2020/21):")), + "in contact with Mental Health Services ", + EQ1_ScotlandHub_dateText, ":")), width = 4, solidHeader = TRUE, # Body text - paste0(EQ1,"x general"), + paste0(EQ1_ScotlandHub_value,"x general"), # Navigation button actionButton(inputId = "EQ1_button", label = "EQ1 - Find out more", @@ -316,10 +326,10 @@ tabItem(tabName = "scot_hub", # Header Text title = tagList(icon("clipboard"), paste0("EQ2 - Number of Emergency Detention Certificates ", - "per 100,000 population (2020/21):")), + "per 100,000 population ", EQ2_ScotlandHub_dateText, ":")), width = 4, solidHeader = TRUE, # Body text - paste0(EQ2), + paste0(EQ2_ScotlandHub_value), # Navigation button actionButton(inputId = "EQ2_button", label = "EQ2 - Find out more", @@ -332,10 +342,11 @@ tabItem(tabName = "scot_hub", paste0("EQ3 - % of people with Severe and Enduring ", "Mental Illness and/or Learning Disability ", "who have had an annual health check within ", - "previous 12 months:")), + "previous 12 months ", + EQ3_ScotlandHub_dateText, ":")), width = 4, solidHeader = TRUE, # Body text - paste0("Two NHS Boards advised: ", EQ3,"%"), + paste0("Two NHS Boards advised: ", EQ3_ScotlandHub_value, "%"), # Navigation button actionButton(inputId = "EQ3_button", label = "EQ3 - Find out more", @@ -348,10 +359,11 @@ tabItem(tabName = "scot_hub", title = tagList(icon("child"), paste0( "EQ4 - % of under 18 psychiatric admissions ", - "admitted outwith specialist CAMH wards (Sep 2020 - Sep 2021):")), + "admitted outwith specialist CAMH wards ", + EQ4_ScotlandHub_dateText, ":")), width = 4, solidHeader = TRUE, # Body text - paste0(EQ4,"%"), + paste0(EQ4_ScotlandHub_value, "%"), # Navigation button actionButton(inputId = "EQ4_button", label = "EQ4 - Find out more", diff --git a/scot_hub_data.R b/scot_hub_data.R index bcbd02f..4bdd4cb 100755 --- a/scot_hub_data.R +++ b/scot_hub_data.R @@ -1,56 +1,289 @@ -# Constants ---------------------------------------------------- +# NEW CODE (OLD BELOW) ---- + +# Load alt text csv ---- + +alt_text_csv <- read.csv("//PHI_conf/MentalHealth1/Quality Indicators/QI Publication/2024_November/Dashboard Data/Indicator text/WIP_alt_text_for_indicators.csv") + + +# T1 ---- +# % of people who commence Psychological therapy-based treatment within 18 weeks of referral +T1_ScotlandHub_dateText <- alt_text_csv %>% + filter(alt_text == "T1_ScotlandHub_dateText") %>% + pull(value) + +T1_ScotlandHub_value <- alt_text_csv %>% + filter(alt_text == "T1_ScotlandHub_value") %>% + pull(value) + + +# T2 ---- +# % of young people who commence treatment by specialist Child and Adolescent Mental Health +# services within 18 weeks of referral + +T2_ScotlandHub_dateText <- alt_text_csv %>% + filter(alt_text == "T2_ScotlandHub_dateText") %>% + pull(value) + +T2_ScotlandHub_value <- alt_text_csv %>% + filter(alt_text == "T2_ScotlandHub_value") %>% + pull(value) + + +# T3 ---- +# % of people who wait less than three weeks from referral received to appropriate drug or +# alcohol treatment that supports their recovery + +T3_ScotlandHub_dateText <- alt_text_csv %>% + filter(alt_text == "T3_ScotlandHub_dateText") %>% + pull(value) + + +T3_ScotlandHub_value <- alt_text_csv %>% + filter(alt_text == "T3_ScotlandHub_value") %>% + pull(value) + + +# S1 ---- +# Suicide rates per 100,000 population + +S1_ScotlandHub_dateText <- alt_text_csv %>% + filter(alt_text == "S1_ScotlandHub_dateText") %>% + pull(value) + +S1_ScotlandHub_value <- alt_text_csv %>% + filter(alt_text == "S1_ScotlandHub_value") %>% + pull(value) + + + +# S2 - currently no data in folder ---- +# % of all discharged psychiatric inpatients followed-up by community mental health services +# within 7 calendar days +S2_ScotlandHub_dateText <- "(Oct-Dec 2021)" + +S2_ScotlandHub_value_low <- 17.6 + +S2_ScotlandHub_value_high <- 88.1 + + +# S5 - currently no data in folder ---- +# Incidents of physical violence per 1,000 occupied psychiatric bed days + +S5_ScotlandHub_dateText <- "(Oct-Dec 2021)" +S5_ScotlandHub_value_low <- "Zero" +S2_ScotlandHub_value_high <- 40.3 + + +# P1 - update manually ---- +# % of carers with a mental health condition that felt supported to continue in their caring role + +P1_ScotlandHub_dateText <- "(In financial year 2023/24)" + +P1_ScotlandHub_value <- "27%" + + +# P2 - update manually ---- +# % of adults with mental health problems supported at home who agree that their services and +# support had an impact in improving or maintaining their quality of life + +P2_ScotlandHub_dateText <- "(In financial year 2023/24)" + +P2_ScotlandHub_value <- "55%" + +# P3 - update manually ---- +# % of replies for people with a mental health problem that agree with the statement +# "people took account of the things that mattered to me" + +P3_ScotlandHub_dateText <- "(In financial year 2023/24)" + +P3_ScotlandHub_value <- "56%" -# Data for Scot Hub (from previous publication): -T1_dateText <- "(Oct-Dec 2021)" -T1 <- 84.4 -T2_dateText <- "(Oct-Dec 2021)" -T2 <- 70.3 +# P4 ---- +# Number of people with advance statements registered per year with the +# Mental Welfare Commission for Scotland -T3_dateText <- "(Oct-Dec 2021)" -T3 <- 93 +P4_ScotlandHub_dateText <- alt_text_csv %>% + filter(alt_text == "P4_ScotlandHub_dateText") %>% + pull(value) +P4_ScotlandHub_value <- alt_text_csv %>% + filter(alt_text == "P4_ScotlandHub_value") %>% + pull(value) -S1_dateText <- "(2016-2020)" -S1 <- 13.7 -S2_dateText <- "(Oct-Dec 2021)" -S2_low <- 17.6 -S2_high <- 88.1 +# E1 ---- +# Number of days people spend in hospital when they are clinically ready to +# be discharged per 1,000 population -S5_dateText <- "(Oct-Dec 2021)" -S5_low <- "Zero" -S5_high <- 40.3 +E1_ScotlandHub_dateText <- alt_text_csv %>% + filter(alt_text == "E1_ScotlandHub_dateText") %>% + pull(value) -P1_dateText <- "(2019/20)" -P1 <- 27 +E1_ScotlandHub_value <- alt_text_csv %>% + filter(alt_text == "E1_ScotlandHub_value") %>% + pull(value) -P2_dateText <- "(2019/20)" -P2 <- 74 -P3_dateText <- "(2019/20)" -P3 <- 78 +# EF1 ---- +# Rate of emergency bed days for adults (per 100,000 population) -P4_dateText <- "2020/21" -P4 <- 78 - -E1_orig <- 13829462 # [remember to add code to include 000 separarators] -E1 <- format(E1_orig, big.mark = ",") +EF1_ScotlandHub_dateText <- alt_text_csv %>% + filter(alt_text == "EF1_ScotlandHub_dateText") %>% + pull(value) -EF1 <- "18,844" -EF2 <- 8.4 -EF3 <- 64.9 +EF1_ScotlandHub_value <- alt_text_csv %>% + filter(alt_text == "EF1_ScotlandHub_value") %>% + pull(value) -EF4 <- 8.8 -EF4_text <- "(2020/21)" -EF5_low <- 8.2 -EF5_high <- 20.5 +# EF2 ---- +# % Readmissions to hospital within 28 days of discharge -EQ1 <- 2.62 +EF2_ScotlandHub_dateText <- alt_text_csv %>% + filter(alt_text == "EF2_ScotlandHub_dateText") %>% + pull(value) -EQ2 <- 60 +EF2_ScotlandHub_value <- alt_text_csv %>% + filter(alt_text == "EF2_ScotlandHub_value") %>% + pull(value) + + +# EF3 - working on, have half the data ---- +# Total psychiatric inpatient beds per 100,000 population (NRAC adjusted) + +EF3_ScotlandHub_dateText <- "(in EXAMPLE DATE)" + + +EF3_ScotlandHub_value <- 64.9 + + +# EF4 ---- +# Total mental health spend as a % of total spend + +EF4_ScotlandHub_dateText <- alt_text_csv %>% + filter(alt_text == "EF4_ScotlandHub_dateText") %>% + pull(value) + + +EF4_ScotlandHub_value <- alt_text_csv %>% + filter(alt_text == "EF4_ScotlandHub_value") %>% + pull(value) + + +# EF5 - currently no data in folder ---- +# % of did not attend appointments for community based services of people with mental +# health problems + +EF5_ScotlandHub_dateText <- "(EXAMPLE DATE)" + +EF5_ScotlandHub_value_low <- 8.2 +EF5_ScotlandHub_value_high <- 20.5 + + +# EQ1 ---- +# Premature mortality rate = Standardised mortality rate for persons in contact with +# mental health services + +EQ1_ScotlandHub_dateText <- alt_text_csv %>% + filter(alt_text == "EQ1_ScotlandHub_dateText") %>% + pull(value) + +EQ1_ScotlandHub_value <- alt_text_csv %>% + filter(alt_text == "EQ1_ScotlandHub_value") %>% + pull(value) + + +# EQ2 ---- +# Number of emergency detention certificates (EDCs) per 100,000 population + +EQ2_ScotlandHub_dateText <- alt_text_csv %>% + filter(alt_text == "EQ2_ScotlandHub_dateText") %>% + pull(value) + +EQ2_ScotlandHub_value <- alt_text_csv %>% + filter(alt_text == "EQ2_ScotlandHub_value") %>% + pull(value) + + +# EQ3 - new indicator - need to find data ---- +# % of people with Severe and Enduring Mental Illness and/or Learning Disability who have +# had an annual health check within previous 12 months + +EQ3_ScotlandHub_dateText <- "(EXAMPLE DATE)" + +EQ3_ScotlandHub_value <- 6 + + +# EQ4 ---- +# % of under 18 year old psychiatric admissions admitted out with NHS specialist Child and +# Adolescent Mental Health (CAMH) wards + +EQ4_ScotlandHub_dateText <- alt_text_csv %>% + filter(alt_text == "EQ4_ScotlandHub_dateText") %>% + pull(value) + +EQ4_ScotlandHub_value <- alt_text_csv %>% + filter(alt_text == "EQ4_ScotlandHub_value") %>% + pull(value) + + + +# OLD CODE copied out ---- + +# Constants ---------------------------------------------------- + +# Data for Scot Hub (from previous publication): +# T1_dateText <- "(Oct-Dec 2021)" +# T1 <- 84.4 -EQ3 <- 6 - -EQ4 <- 51.3 +# T2_dateText <- "(Oct-Dec 2021)" +# T2 <- 70.3 +# +# T3_dateText <- "(Oct-Dec 2021)" +# T3 <- 93 +# +# +# S1_dateText <- "(2016-2020)" +# S1 <- 13.7 +# +# S2_dateText <- "(Oct-Dec 2021)" +# S2_low <- 17.6 +# S2_high <- 88.1 +# +# S5_dateText <- "(Oct-Dec 2021)" +# S5_low <- "Zero" +# S5_high <- 40.3 +# +# P1_dateText <- "(2019/20)" +# P1 <- 27 +# +# P2_dateText <- "(2019/20)" +# P2 <- 74 +# +# P3_dateText <- "(2019/20)" +# P3 <- 78 +# +# P4_dateText <- "2020/21" +# P4 <- 78 +# +# E1_orig <- 13829462 # [remember to add code to include 000 separarators] +# E1 <- format(E1_orig, big.mark = ",") +# +# EF1 <- "18,844" +# EF2 <- 8.4 +# EF3 <- 64.9 +# +# EF4 <- 8.8 +# EF4_text <- "(2020/21)" +# +# EF5_low <- 8.2 +# EF5_high <- 20.5 +# +# EQ1 <- 2.62 +# +# EQ2 <- 60 +# +# EQ3 <- 6 +# +# EQ4 <- 51.3 \ No newline at end of file