diff --git a/app.R b/app.R index d642b00..c601b3b 100644 --- a/app.R +++ b/app.R @@ -25,16 +25,13 @@ library(DT) library(shinymanager) # password protection library(readxl) library(lubridate) +library(scales) # for comma ef1 # Data import section ---------------------------------------------------- # Source data source("data_preparation.R") -# Source constants used throughout app -source("indicator_alt_text.R") -source("scot_hub_data.R") - # Source functions created for app (see functions folder) ------------------------------- list.files("functions") %>% map(~ source(paste0("functions/", .))) @@ -136,6 +133,9 @@ server <- function(input, output, session) { # Navigation buttons ---- source("modules/nav_buttons_server.R", local = TRUE) + # Scothub + source("modules/scot_hub_server.R", local = TRUE) + # Data downloads ---- source("modules/data_server.R", local = TRUE) diff --git a/modules/indicators/EF3_ui.R b/modules/indicators/EF3_ui.R index bb782d8..18a6150 100644 --- a/modules/indicators/EF3_ui.R +++ b/modules/indicators/EF3_ui.R @@ -6,7 +6,8 @@ tabItem(tabName = "EF3_tab", box(width = 9, img(src='infographics/EF3.png', class = "infographic", - alt = EF3_infographic_alt_text) + alt = "The total number of average available staffed beds per day for all psychiatric specialties in 2024/25 in Scotland was 3,527 beds (i.e. 64.1 psychiatric beds per 100,000 population). + This is a decrease from 64.9 beds per 100,000 population in 2023/24 and 66.7 beds per 100,000 population in 2022/23.") ) ), diff --git a/modules/indicators/EQ2_ui.R b/modules/indicators/EQ2_ui.R index 3f7fe25..ac40a57 100644 --- a/modules/indicators/EQ2_ui.R +++ b/modules/indicators/EQ2_ui.R @@ -6,7 +6,7 @@ tabItem(tabName = "EQ2_tab", box(width = 9, img(src='infographics/EQ2.png', class = "infographic", - alt = EQ2_infographic_alt_text) + alt = "In Scotland in 2024/25, the number of emergency detention certificates per 100,000 population was 69.8. This is a slight increase from 66.8 in 2023/24.") ) ), diff --git a/modules/indicators/P1_ui.R b/modules/indicators/P1_ui.R index 9954078..006e2c0 100644 --- a/modules/indicators/P1_ui.R +++ b/modules/indicators/P1_ui.R @@ -7,7 +7,8 @@ tabItem(tabName = "P1_tab", box(width = 9, img(src='infographics/P1.png', class = "infographic", - alt = P1_infographic_alt_text) + alt = "In Scotland in 2025/26 26% (confidence interval: 24%; 28%) of carers with a mental health + condition agreed that they felt supported to continue caring. This compares with 27% of carers with a mental health condition in 2023/24.") ) diff --git a/modules/indicators/P2_ui.R b/modules/indicators/P2_ui.R index ff1b6e8..a4998b6 100644 --- a/modules/indicators/P2_ui.R +++ b/modules/indicators/P2_ui.R @@ -7,7 +7,8 @@ tabItem(tabName = "P2_tab", box(width = 9, img(src='infographics/P2.png', class = "infographic", - alt = P2_infographic_alt_text)) + alt = "In Scotland in 2025/26 55% (confidence interval: 53%; 57%) of adults with a mental health condition supported at home agree that their services and support had an + impact in improving or maintaining their quality of life. There was no change from the last available figure (55%) in 2023/24. ")) ), fluidRow( diff --git a/modules/indicators/P3_ui.R b/modules/indicators/P3_ui.R index 7561112..b93597e 100644 --- a/modules/indicators/P3_ui.R +++ b/modules/indicators/P3_ui.R @@ -7,7 +7,8 @@ tabItem(tabName = "P3_tab", box(width = 9, img(src='infographics/P3.png', class = "infographic", - alt = P3_infographic_alt_text)) + alt = "In Scotland in 2025/26 56% (confidence interval: 53%; 58%) of people with a mental health condition agreed + that people took account of the things that mattered to them. There was no change from the last available figure (56%) in 2023/24.")) ), diff --git a/modules/indicators/P4_ui.R b/modules/indicators/P4_ui.R index e0473bb..437cc68 100644 --- a/modules/indicators/P4_ui.R +++ b/modules/indicators/P4_ui.R @@ -9,7 +9,8 @@ tabItem(tabName = "P4_tab", box(width = 9, img(src='infographics/P4.png', class = "infographic", - alt = P4_infographic_alt_text) + alt = "In Scotland in 2024/25, there were 175 new advance statements registered with MWC, + this compares with 153 new statements in 2023/24, 162 new statements in 2022/23 and 117 in 2021/22.") ) ), diff --git a/modules/indicators/T1_ui.R b/modules/indicators/T1_ui.R index 3eb8d39..1c192a0 100644 --- a/modules/indicators/T1_ui.R +++ b/modules/indicators/T1_ui.R @@ -6,7 +6,8 @@ tabItem(tabName = "T1_tab", box(width = 9, img(src='infographics/T1.png', class = "infographic", - alt = T1_infographic_alt_text) + alt = "Over three quarters (78.3%) of people started treatment within 18 weeks of referral in the quarter ending 30 June 2025, + compared to 78.6% for the previous quarter, and 80.2% for the quarter ending 30 June 2024.") ) ), diff --git a/modules/indicators/T2_ui.R b/modules/indicators/T2_ui.R index d426f1f..0c0a916 100644 --- a/modules/indicators/T2_ui.R +++ b/modules/indicators/T2_ui.R @@ -8,7 +8,9 @@ tabItem(tabName = "T2_tab", box(width = 9, img(src='infographics/T2.png', class = "infographic", - alt = T2_infographic_alt_text) + alt = "Over nine-tenths (91.8%) of children and young people started treatment within 18 weeks of referral in the quarter ending 30 June 2025. + This is an increase from 91.6% in the previous quarter and 84.1% for the quarter ending 30 June 2024. + Half of children and young people started treatment within 5 weeks in the quarter ending 30 June 2025.") ) ), diff --git a/modules/indicators/T3_ui.R b/modules/indicators/T3_ui.R index d8a579b..98726d8 100644 --- a/modules/indicators/T3_ui.R +++ b/modules/indicators/T3_ui.R @@ -8,7 +8,9 @@ tabItem(tabName = "T3_tab", box(width = 9, img(src='infographics/T3.png', class = "infographic", - alt = paste0(T3_infographic_alt_text)) + alt = "Of the 7,041 referrals to community-based specialist drug and alcohol treatment services starting treatment in the + quarter ending 30 June 2025, 94.3% involved a wait of three weeks of less. + The percentage of treatment within three weeks for drug treatment was 96.2% and 92.8% for alcohol treatment.") ) ), diff --git a/modules/scot_hub_server.R b/modules/scot_hub_server.R new file mode 100644 index 0000000..3c7b310 --- /dev/null +++ b/modules/scot_hub_server.R @@ -0,0 +1,334 @@ +### [Scot hub server] ---------------------------------------------------- + +# S1 pull latest year figure ---- +latest_data <- reactive({ + S1_data %>% + mutate(year = as.numeric(as.character(year))) %>% + filter(year == max(year, na.rm = TRUE)) %>% + select(year, suicide_rate) +}) + +# Dynamic title +output$s1_title <- renderUI({ + data <- latest_data() + if (nrow(data) == 0) return(NULL) + latest_year <- data$year[1] + tagList( + icon("chart-line"), + paste0( + "S1 - Suicide rate per 100,000 population (calendar year ", + latest_year, "):" + ) + ) +}) + +# Dynamic value +output$s1_value <- renderUI({ + data <- latest_data() + if (nrow(data) == 0) return(NULL) + strong(round(data$suicide_rate[1], 1)) +}) + + +# S2 pull highest to lowest value latest quarter figures ---- +latest_data_s2 <- reactive({ + req(S2_data) # Replace with your actual dataset variable + + S2_data %>% + filter(year_quarter == max(year_quarter, na.rm = TRUE)) %>% + summarise( + min_val = min(percentage_followed_up, na.rm = TRUE), + max_val = max(percentage_followed_up, na.rm = TRUE), + latest_quarter = first(year_quarter) + ) +}) + +# Dynamic title +output$s2_title <- renderUI({ + data <- latest_data_s2() + if (nrow(data) == 0) return(NULL) + + tagList( + icon("brain"), + paste0( + "S2 - % of all discharged psychiatric inpatients ", + "followed-up by community mental health services ", + "within 7 calendar days (", data$latest_quarter, "):" + ) + ) +}) + +# Dynamic value +output$s2_value <- renderUI({ + data <- latest_data_s2() + if (nrow(data) == 0) return(NULL) + + min_val <- round(data$min_val, 1) + max_val <- round(data$max_val, 1) + + strong( + paste0(min_val, "% to ", max_val, "% across health boards") + ) +}) + +# S5 pull highest to lowest latest quarter figures ---- +latest_data_s5 <- reactive({ + req(S5_data) # Replace with your actual dataset variable + + S5_data %>% + filter(year_quarter == max(year_quarter, na.rm = TRUE)) %>% + summarise( + min_val = min(incidents_per_1000_bed_days, na.rm = TRUE), + max_val = max(incidents_per_1000_bed_days, na.rm = TRUE), + latest_quarter = first(year_quarter) + ) +}) + +# Title output +output$s5_title <- renderUI({ + data <- latest_data_s5() + if (nrow(data) == 0) return(NULL) + + tagList( + icon("hand-fist"), + paste0( + "S5 - Incidents of physical violence per ", + "1,000 occupied psychiatric bed days (", data$latest_quarter, "):" + ) + ) +}) + +# Dynamic value +output$s5_value <- renderUI({ + data <- latest_data_s5() + if (nrow(data) == 0) return(NULL) + + min_val <- round(data$min_val, 1) + max_val <- round(data$max_val, 1) + + strong( + paste0(min_val, " to ", max_val, " across health boards") + ) +}) + +# E1 pull latest year figure for Scotland ---- +latest_data_e1 <- reactive({ + E1_data %>% + filter(area_name == "Scotland", + as.character(fyear) == max(as.character(fyear))) |> + select(fyear, rate_per_1000_population) +}) + +# Dynamic title +output$e1_title <- renderUI({ + data <- latest_data_e1() + if (nrow(data) == 0) return(NULL) + latest_fyear <- data$fyear[1] + tagList( + icon("hospital"), + paste0("E1 - Days in hospital when clinically + ready to discharge, per 1,000 population (In financial year ", + latest_fyear, "):" + ) + ) +}) + +# Dynamic value +output$e1_value <- renderUI({ + data <- latest_data_e1() + if (nrow(data) == 0) return(NULL) + strong(round(data$rate_per_1000_population[1], 1)) +}) + +# EF1 pull latest quarter figure for Scotland ---- +latest_data_ef1 <- reactive({ + EF1_data %>% + filter(hb_name == "NHS Scotland", + as.integer(year_months) == max(as.integer(year_months))) |> + select(year_months, bedday_rate) +}) + +# Dynamic title +output$ef1_title <- renderUI({ + data <- latest_data_ef1() + if (nrow(data) == 0) return(NULL) + latest_quarter <- data$year_months[1] + tagList( + icon("bed-pulse"), + paste0("EF1 - Rate of emergency bed days for adults per 100,000 population (", + latest_quarter, "):" + ) + ) +}) + +# Dynamic value +output$ef1_value <- renderUI({ + data <- latest_data_ef1() + if (nrow(data) == 0) return(NULL) + + # add comma and round to 1dp + formatted_value <- comma(round(data$bedday_rate[1], 1)) + + strong(formatted_value) +}) + + +# EF2 pull latest quarter figure for Scotland ---- +latest_data_ef2 <- reactive({ + EF2_data %>% + filter(Board == "NHS Scotland", + as.integer(year_months) == max(as.integer(year_months))) |> + select(year_months, x28_days_readmission_rate_percentage_quarter) +}) + +# Dynamic title +output$ef2_title <- renderUI({ + data <- latest_data_ef2() + if (nrow(data) == 0) return(NULL) + latest_quarter <- data$year_months[1] + tagList( + icon("arrows-rotate"), + paste0("EF2 - % of readmissions to hospital within 28 days of discharge (", + latest_quarter, "):" + ) + ) +}) + +# Dynamic value +output$ef2_value <- renderUI({ + data <- latest_data_ef2() + if (nrow(data) == 0) return(NULL) + + strong(paste0(round(data$x28_days_readmission_rate_percentage_quarter[1], 1), "%")) +}) + +# EF4 pull latest year figure for Scotland ---- +latest_data_ef4 <- reactive({ + EF4_data %>% + filter(hb_name == "NHS Scotland", + measure == "Mental Health Expenditure", + as.character(fyear) == max(as.character(fyear))) |> + select(fyear, value) +}) + +# Dynamic title +output$ef4_title <- renderUI({ + data <- latest_data_ef4() + if (nrow(data) == 0) return(NULL) + latest_fyear <- data$fyear[1] + tagList( + icon("sterling-sign"), + paste0("EF4 - Total mental health spend as a % of total NHS spend (In financial year ", + latest_fyear, "):" + ) + ) +}) + +# Dynamic value +output$ef4_value <- renderUI({ + data <- latest_data_ef4() + if (nrow(data) == 0) return(NULL) + + strong(paste0(round(data$value[1], 2), "%")) +}) + +# EF5 pull highest to lowest latest quarter figures ---- +latest_data_ef5 <- reactive({ + req(EF5_data) # Replace with your actual dataset variable + + EF5_data %>% + filter(measure == "Percentage 'Did Not Attend' appointments", + as.integer(year_months) == max(as.integer(year_months))) |> + summarise( + min_val = min(value, na.rm = TRUE), + max_val = max(value, na.rm = TRUE), + latest_quarter = first(year_months)) +}) + +# Title output +output$ef5_title <- renderUI({ + data <- latest_data_s5() + if (nrow(data) == 0) return(NULL) + + tagList( + icon("circle-xmark"), + paste0( + "EF5 - % of 'did not attend appointments' for ", + "community based services (Mental Health ", data$latest_quarter, "):" + ) + ) +}) + +# Dynamic value +output$ef5_value <- renderUI({ + data <- latest_data_ef5() + if (nrow(data) == 0) return(NULL) + + min_val <- round(data$min_val, 1) + max_val <- round(data$max_val, 1) + + strong( + paste0(min_val, "% to ", max_val, "% across health boards") + ) +}) + +#EQ1 pull latest year figure ---- +latest_data_eq1 <- reactive({ + EQ1_data %>% + filter(area_name == "NHS Scotland") |> + mutate(Year = as.numeric(as.character(Year))) |> + filter(Year == max(Year, na.rm = TRUE)) |> + select(Year, risk_ratio) +}) + +# Dynamic title +output$eq1_title <- renderUI({ + data <- latest_data_eq1() + if (nrow(data) == 0) return(NULL) + latest_year <- data$Year[1] + tagList( + icon("chart-column"), + paste0( + "EQ1 - Premature mortality rate for persons ", + "in contact with mental health services (In calendar year ", + latest_year, "):" + ) + ) +}) + +# Dynamic value +output$eq1_value <- renderUI({ + data <- latest_data_eq1() + if (nrow(data) == 0) return(NULL) + strong(round(data$risk_ratio[1], 2), "times higher than the general population") +}) + +#EQ4 pull latest year figure ---- +latest_data_eq4 <- reactive({ + EQ4_data %>% + filter(board == "NHS Scotland", + as.character(quarter_fy) == max(as.character(quarter_fy))) |> + select(quarter_fy, perc) +}) + +# Dynamic title +output$eq4_title <- renderUI({ + data <- latest_data_eq4() + if (nrow(data) == 0) return(NULL) + latest_quarter <- data$quarter_fy[1] + tagList( + icon("hands-holding-child"), + paste0("EQ4 - % of under 18 psychiatric admissions ", + "admitted outwith specialist CAMH wards (", + latest_quarter, "):" + ) + ) +}) + +# Dynamic value +output$eq4_value <- renderUI({ + data <- latest_data_eq4() + if (nrow(data) == 0) return(NULL) + + strong(paste0(round(data$perc[1], 1), "%")) +}) \ No newline at end of file diff --git a/modules/scot_hub_ui.R b/modules/scot_hub_ui.R index b9de16c..627cd49 100644 --- a/modules/scot_hub_ui.R +++ b/modules/scot_hub_ui.R @@ -1,376 +1,370 @@ -tabItem(tabName = "scot_hub", - - h1("Scotland Hub"), + tabItem(tabName = "scot_hub", + + h1("Scotland Hub"), + +### [Timely] --------------------------- + +h2("Timely"), +fluidRow( + box(## T1 ---- + # Header Text + title = tagList(icon("hospital-user"), + # 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 ", + "(April-June 2025)", ":")), + width = 4, solidHeader = TRUE, + # Body text + paste0("78.3%"), + # Navigation button + actionButton(inputId = "T1_button", + label = "T1 - Find out more", + class = "navpageButton pull-right") + # N.B. pull-right class keeps the actionButton aligned right but within the box boundaries + ), + + box(## T2 ---- + # Header Text + title = tagList(icon("children"), + paste0( + "T2 - % of young people who commence treatment by ", + "specialist Child and Adolescent Mental Health ", + "Services within 18 weeks of referral ", + "(April-June 2025)",":")), + width = 4, solidHeader = TRUE, + # Body text + paste0("91.8%"), + # Navigation button + actionButton(inputId = "T2_button", + label = "T2 - Find out more", + class = "navpageButton pull-right") + ), + + box(## T3 ---- + # Header Text + title = tagList(icon("wine-bottle"), + paste0( + "T3 - % of people who wait less than three weeks ", + "from referral received to appropriate drug or ", + "alcohol treatment that supports their recovery ", + "(April-June 2025)",":")), + width = 4, solidHeader = TRUE, + # Body text + paste0("94.3%"), + # Navigation button + actionButton(inputId = "T3_button", + label = "T3 - Find out more", + class = "navpageButton pull-right") + ) +), + +br(), - ### [Timely] --------------------------- - - h2("Timely"), - fluidRow( - box(## T1 ---- - # Header Text - title = tagList(icon("hospital-user"), - # 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_ScotlandHub_dateText, ":")), - width = 4, solidHeader = TRUE, - # Body text - paste0(T1_ScotlandHub_value,"%"), - # Navigation button - actionButton(inputId = "T1_button", - label = "T1 - Find out more", - class = "navpageButton pull-right") - # N.B. pull-right class keeps the actionButton aligned right but within the box boundaries - ), - - box(## T2 ---- - # Header Text - title = tagList(icon("children"), - paste0( - "T2 - % of young people who commence treatment by ", - "specialist Child and Adolescent Mental Health ", - "Services within 18 weeks of referral ", - T2_ScotlandHub_dateText,":")), - width = 4, solidHeader = TRUE, - # Body text - paste0(T2_ScotlandHub_value,"%"), - # Navigation button - actionButton(inputId = "T2_button", - label = "T2 - Find out more", - class = "navpageButton pull-right") - ), - - box(## T3 ---- - # Header Text - title = tagList(icon("wine-bottle"), - paste0( - "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,":")), - width = 4, solidHeader = TRUE, - # Body text - paste0(T3_ScotlandHub_value,"%"), - # Navigation button - actionButton(inputId = "T3_button", - label = "T3 - Find out more", - class = "navpageButton pull-right") - ) - ), - - br(), - ### [Safe] --------------------------- - - h2("Safe"), - fluidRow( - - box(## S1 ---- - # Header Text - title = tagList(icon("chart-line"), - paste0( - "S1 - Suicide rate per 100,000 population (calendar year ", - S1_ScotlandHub_dateText,"):")), - width = 4, solidHeader = TRUE, - # Body text - paste0(S1_ScotlandHub_value), - # Navigation button - actionButton(inputId = "S1_button", - label = "S1 - Find out more", - class = "navpageButton pull-right") - ), - - box(## S2 ---- - # Header Text - title = tagList(icon("brain"), - paste0("S2 - % of all discharged psychiatric inpatients ", - "followed-up by community mental health services ", - "within 7 calendar days ", S2_ScotlandHub_dateText,":")), - width = 4, solidHeader = TRUE, - # Body text - paste0(S2_ScotlandHub_value), - # Navigation button - actionButton(inputId = "S2_button", - label = "S2 - Find out more", - class = "navpageButton pull-right") - ), - - box(## S5 ---- - # Header Text - title = tagList(icon("hand-fist"), - paste0( - "S5 - Incidents of physical violence per ", - "1,000 occupied psychiatric bed days ", - S5_ScotlandHub_dateText,":")), - width = 4, solidHeader = TRUE, - # Body text - paste0(S5_ScotlandHub_value), - # Navigation button - actionButton(inputId = "S5_button", - label = "S5 - Find out more", - class = "navpageButton pull-right") - ) - ), - - br(), - - ### [Person Centred] --------------------------- - - h2("Person Centred"), - fluidRow( - - box(## P1 ---- - # Header Text - title = tagList(icon("hand-holding-hand"), - paste0( - "P1 - % of carers with a mental health condition that felt ", - "supported to continue in their caring role ", - P1_ScotlandHub_dateText,":")), + h2("Safe"), + fluidRow( + box(## S1 ---- + title = uiOutput("s1_title"), # dynamic title + width = 4, solidHeader = TRUE, + # Row with value on the left and button on the right + div( + style = "display: flex; justify-content: space-between; align-items: center; height: 40px; margin-top: 5px;", + div( + uiOutput("s1_value") + ), # dynamic value + actionButton( + inputId = "S1_button", + label = "S1 - Find out more", + class = "navpageButton pull-right" + ))), + + box(## S2 ---- + title = uiOutput("s2_title"), # dynamic title + width = 4, solidHeader = TRUE, + # Row with value on the left and button on the right + div( + style = "display: flex; justify-content: space-between; align-items: center; height: 40px; margin-top: 5px;", + div( + uiOutput("s2_value") + ), # dynamic value + actionButton( + inputId = "S2_button", + label = "S2 - Find out more", + class = "navpageButton pull-right" + ))), + + box( ## S5 ---- + title = uiOutput("s5_title"), # dynamic title + width = 4, solidHeader = TRUE, + div( + style = "display: flex; justify-content: space-between; align-items: center; height: 40px; margin-top: 5px;", - width = 4, solidHeader = TRUE, - # Body text - paste0(P1_ScotlandHub_value), - # Navigation button - actionButton(inputId = "P1_button", - label = "P1 - Find out more", - class = "navpageButton pull-right") - ), - - box(## P2 ---- - # Header Text - title = tagList( - icon("house-medical-circle-check"), - 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_ScotlandHub_dateText,":")), - width = 4, solidHeader = TRUE, - # Body text - paste0(P2_ScotlandHub_value), - # Navigation button - actionButton(inputId = "P2_button", - label = "P2 - Find out more", - class = "navpageButton pull-right") - ), - - box(## P3 ---- - # Header Text - title = tagList( - icon("hand-holding-heart"), - paste0( - 'P3 - % of people with a MH problem that agree ', - 'with the statement "people took account of the things ', - 'that mattered to me" ', P3_ScotlandHub_dateText,":")), - width = 4, solidHeader = TRUE, - # Body text - paste0(P3_ScotlandHub_value), - # Navigation button - actionButton(inputId = "P3_button", - label = "P3 - Find out more", - class = "navpageButton pull-right") - ), - - box(## P4 ---- - # Header Text - title = tagList( - icon("clipboard-user"), - paste0("P4 - Number of people with advance statements ", - "registered with the Mental Welfare Commission for Scotland ", - P4_ScotlandHub_dateText,":")), - width = 4, solidHeader = TRUE, - # Body text - paste0(P4_ScotlandHub_value), - # Navigation button - actionButton(inputId = "P4_button", - label = "P4 - Find out more", - class = "navpageButton pull-right") - - )), - - br(), - - ### [Effective] --------------------------- - - h2("Effective"), - fluidRow( - - box(## E1 ---- - title = tagList( - icon("hospital"), - paste0("E1 - Days in hospital when clinically - ready to discharge, per 1,000 population ", - E1_ScotlandHub_dateText, ":")), - width = 4, solidHeader = TRUE, - # Body text - paste0(E1_ScotlandHub_value), - # Navigation button - actionButton(inputId = "E1_button", - label = "E1 - Find out more", - class = "navpageButton pull-right") - - )), - - br(), - - ### [Efficient] --------------------------- - - h2("Efficient"), - fluidRow( - - box(## EF1 ---- - # Header Text - title = tagList( - icon("bed-pulse"), - "EF1 - Rate of emergency bed days for adults per 100,000 population ", - EF1_ScotlandHub_dateText, ":"), - width = 4, solidHeader = TRUE, - # Body text - paste0(EF1_ScotlandHub_value), - # Navigation button - actionButton(inputId = "EF1_button", - label = "EF1 - Find out more", - class = "navpageButton pull-right") - ), + # Value text on the left + div( + uiOutput("s5_value") + ), + + # Action button on the right + actionButton( + inputId = "S5_button", + label = "S5 - Find out more", + class = "navpageButton" + ) + ) + )), + + + br(), + + ### [Person Centred] --------------------------- + + h2("Person Centred"), + fluidRow( + + box(## P1 ---- + # Header Text + title = tagList(icon("hand-holding-hand"), + paste0( + "P1 - % of carers with a mental health condition that felt ", + "supported to continue in their caring role ", + "(In financial year 2025/26)",":")), - box(## EF2 ---- - # Header Text - title = tagList( - icon("arrows-rotate"), - paste0("EF2 - % of readmissions to hospital within 28 days of discharge ", - EF2_ScotlandHub_dateText, ":") - ), - width = 4, solidHeader = TRUE, - # Body text - paste0(EF2_ScotlandHub_value, "%"), - # Navigation button - actionButton(inputId = "EF2_button", - label = "EF2 - Find out more", - class = "navpageButton pull-right") - ), + width = 4, solidHeader = TRUE, + # Body text + paste0("26%"), + # Navigation button + actionButton(inputId = "P1_button", + label = "P1 - Find out more", + class = "navpageButton pull-right") + ), + + box(## P2 ---- + # Header Text + title = tagList( + icon("house-medical-circle-check"), + 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 ", "(In financial year 2025/26)",":")), + width = 4, solidHeader = TRUE, + # Body text + paste0("55%"), + # Navigation button + actionButton(inputId = "P2_button", + label = "P2 - Find out more", + class = "navpageButton pull-right") + ), + + box(## P3 ---- + # Header Text + title = tagList( + icon("hand-holding-heart"), + paste0( + 'P3 - % of people with a MH problem that agree ', + 'with the statement "people took account of the things ', + 'that mattered to me" ', "(In financial year 2025/26)",":")), + width = 4, solidHeader = TRUE, + # Body text + paste0("56%"), + # Navigation button + actionButton(inputId = "P3_button", + label = "P3 - Find out more", + class = "navpageButton pull-right") + ), + + box(## P4 ---- + # Header Text + title = tagList( + icon("clipboard-user"), + paste0("P4 - Number of people with advance statements ", + "registered with the Mental Welfare Commission for Scotland ", + "(In financial year 2024/25)",":")), + width = 4, solidHeader = TRUE, + # Body text + paste0("175"), + # Navigation button + actionButton(inputId = "P4_button", + label = "P4 - Find out more", + class = "navpageButton pull-right") - # EF3 ---- - box( - # Header Text - title = tagList( - icon("bed"), - paste0("EF3 - Total psychiatric inpatient beds per 100,000 population ", - EF3_ScotlandHub_dateText, ":") + )), + +br(), + +### [Effective] --------------------------- + + h2("Effective"), + fluidRow( + box(## E1 ---- + title = uiOutput("e1_title"), # dynamic title + width = 4, solidHeader = TRUE, height = 150, + div( + style = "display: flex; justify-content: space-between; align-items: center; height: 40px; margin-top: 5px;", + + # Value text on the left + div( + uiOutput("e1_value") + ), + actionButton( + inputId = "E1_button", + label = "E1 - Find out more", + class = "navpageButton pull-right" + )))), + + br(), + +### [Efficient] --------------------------- + +h2("Efficient"), +fluidRow( + box( ## EF1 ---- + title = uiOutput("ef1_title"), # dynamic title + width = 4, solidHeader = TRUE, height = 150, + div( + style = "display: flex; justify-content: space-between; align-items: center; height: 40px; margin-top: 5px;", + + # Value text on the left + div( + uiOutput("ef1_value") + ), + + # Action button on the right + actionButton( + inputId = "EF1_button", + label = "EF1 - Find out more", + class = "navpageButton" + ) + )), + + box( ## EF2 ---- + title = uiOutput("ef2_title"), # dynamic title + width = 4, solidHeader = TRUE, height = 150, + div( + style = "display: flex; justify-content: space-between; align-items: center; height: 40px; margin-top: 5px;", + + # Value text on the left + div( + uiOutput("ef2_value") + ), + + # Action button on the right + actionButton( + inputId = "EF2_button", + label = "EF2 - Find out more", + class = "navpageButton" + ) + )), + + + box(## EF3 ---- + # Header Text + title = tagList( + icon("bed"), + paste0("EF3 - Total psychiatric inpatient beds per 100,000 population ", + "(In financial year 2024/25)", ":") + ), + width = 4, solidHeader = TRUE, height = 150, + # Body text + paste0("Total beds: 3,527"), + # Navigation button + actionButton(inputId = "EF3_button", + label = "EF3 - Find out more", + class = "navpageButton pull-right") + ), + + box( ## EF4 ---- + title = uiOutput("ef4_title"), # dynamic title + width = 4, solidHeader = TRUE, height = 150, + div( + style = "display: flex; justify-content: space-between; align-items: center; height: 40px; margin-top: 5px;", + + # Value text on the left + div( + uiOutput("ef4_value") + ), + + # Action button on the right + actionButton( + inputId = "EF4_button", + label = "EF4 - Find out more", + class = "navpageButton" + ) + )), + + box( ## EF5 ---- + title = uiOutput("ef5_title"), # dynamic title + width = 4, solidHeader = TRUE, + div( + style = "display: flex; justify-content: space-between; align-items: center; height: 40px; margin-top: 5px;", + + # Value text on the left + div( + uiOutput("ef5_value") + ), + + # Action button on the right + actionButton( + inputId = "EF5_button", + label = "EF5 - Find out more", + class = "navpageButton" + ) + ) + )), + + + br(), + +### [Equitable] --------------------------- +h2("Equitable"), +fluidRow( + box( ## EQ1 ---- + title = uiOutput("eq1_title"), # dynamic title + width = 4, solidHeader = TRUE, height = 160, + + # Row with value on the left and button on the right + div( + style = "display: flex; justify-content: space-between; align-items: center; height: 40px; margin-top: 5px;", + div( + uiOutput("eq1_value") + ), + actionButton( + inputId = "EQ1_button", + label = "EQ1 - Find out more", + class = "navpageButton" + ) + ) + ), + + box(## EQ2 ---- + # Header Text + title = tagList(icon("scroll"), + paste0("EQ2 - Number of emergency detention certificates ", + "per 100,000 population ", "(In financial year 2024/2025)", ":")), + width = 4, solidHeader = TRUE, height = 160, + # Body text + paste0("69.8"), + # Navigation button + actionButton(inputId = "EQ2_button", + label = "EQ2 - Find out more", + class = "navpageButton pull-right") + ), + + box(## EQ4 ---- + title = uiOutput("eq4_title"), # dynamic title + width = 4, solidHeader = TRUE, height = 160, + # Row with value on the left and button on the right + div( + style = "display: flex; justify-content: space-between; align-items: center; height: 40px; margin-top: 5px;", + div( + uiOutput("eq4_value") ), - width = 4, solidHeader = TRUE, - # Body text - paste0(EF3_ScotlandHub_value), - # Navigation button - actionButton(inputId = "EF3_button", - label = "EF3 - Find out more", - class = "navpageButton pull-right") - ), - - box(# EF4 ---- - # Header Text - title = tagList( - icon("sterling-sign"), - paste0("EF4 - Total mental health spend as a % of total NHS spend ", - EF4_ScotlandHub_dateText, ":")), - width = 4, solidHeader = TRUE, - # Body text - paste0(EF4_ScotlandHub_value, "%"), - # Navigation button - actionButton(inputId = "EF4_button", - label = "EF4 - Find out more", - class = "navpageButton pull-right") - ), - - box(# EF5 ---- - # Header Text - title = tagList(icon("circle-xmark"), - paste0("EF5 - % of 'did not attend appointments' for ", - "community based services (Mental Health ", - EF5_ScotlandHub_dateText, "):") - ), - width = 4, solidHeader = TRUE, - # Body text - paste0("Ranges from: ", EF5_ScotlandHub_value_low,"% - ", - EF5_ScotlandHub_value_high, "%"), - # Navigation button - actionButton(inputId = "EF5_button", - label = "EF5 - Find out more", - class = "navpageButton pull-right") - ) - - ), - - br(), - - ### [Equitable] --------------------------- - - h2("Equitable"), - fluidRow( - - box(## EQ1 ---- - # Header Text - title = tagList(icon("chart-column"), - paste0("EQ1 - Premature mortality rate for persons ", - "in contact with mental health services ", - EQ1_ScotlandHub_dateText, ":")), - width = 4, solidHeader = TRUE, - # Body text - paste0(EQ1_ScotlandHub_value), - # Navigation button - actionButton(inputId = "EQ1_button", - label = "EQ1 - Find out more", - class = "navpageButton pull-right") - ), - - - box(## EQ2 ---- - # Header Text - title = tagList(icon("scroll"), - paste0("EQ2 - Number of emergency detention certificates ", - "per 100,000 population ", EQ2_ScotlandHub_dateText, ":")), - width = 4, solidHeader = TRUE, - # Body text - paste0(EQ2_ScotlandHub_value), - # Navigation button - actionButton(inputId = "EQ2_button", - label = "EQ2 - Find out more", - class = "navpageButton pull-right") - ), -# EQ3 is a new indicator and not being published this year - # box(## EQ3 ---- - # # Header Text - # title = tagList(icon("hourglass-end"), - # 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 ", - # EQ3_ScotlandHub_dateText, ":")), - # width = 4, solidHeader = TRUE, - # # Body text - # paste0("Two NHS Boards advised: ", EQ3_ScotlandHub_value, "%"), - # # Navigation button - # actionButton(inputId = "EQ3_button", - # label = "EQ3 - Find out more", - # class = "navpageButton pull-right") - # ), - - - box(## EQ4 ---- - # Header Text - title = tagList(icon("hands-holding-child"), - paste0( - "EQ4 - % of under 18 psychiatric admissions ", - "admitted outwith specialist CAMH wards ", - EQ4_ScotlandHub_dateText, ":")), - width = 4, solidHeader = TRUE, - # Body text - paste0(EQ4_ScotlandHub_value, "%"), - # Navigation button - actionButton(inputId = "EQ4_button", - label = "EQ4 - Find out more", - class = "navpageButton pull-right") - ) - ) -) # End of tabItem \ No newline at end of file + actionButton( + inputId = "EQ4_button", + label = "EQ4 - Find out more", + class = "navpageButton pull-right" + ))))) + + \ No newline at end of file diff --git a/scot_hub_data.R b/scot_hub_data.R deleted file mode 100755 index 3c50137..0000000 --- a/scot_hub_data.R +++ /dev/null @@ -1,256 +0,0 @@ -# Text and values for using as in the Scotland Hub. -# Data file read into data_preparation.R - -# 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 <- S1_data %>% - filter(year == max(as.character(year))) %>% - pull(year) - -S1_ScotlandHub_value <- S1_data %>% - filter(year == max(as.character(year))) %>% - pull(suicide_rate) - - - -# S2 ---- -# % of all discharged psychiatric inpatients followed-up by community mental health services -# within 7 calendar days - -S2_ScotlandHub_dateText <- alt_text_csv %>% - filter(alt_text == "S2_ScotlandHub_dateText") %>% - pull(value) - -S2_ScotlandHub_value <- alt_text_csv %>% - filter(alt_text == "S2_ScotlandHub_value") %>% - pull(value) - - -# S5 ---- -# Incidents of physical violence per 1,000 occupied psychiatric bed days - -S5_ScotlandHub_dateText <- alt_text_csv %>% - filter(alt_text == "S5_ScotlandHub_dateText") %>% - pull(value) - -S5_ScotlandHub_value <- alt_text_csv %>% - filter(alt_text == "S5_ScotlandHub_value") %>% - pull(value) - - -# P1 ---- -# % of carers with a mental health condition that felt supported to continue in their caring role - -P1_ScotlandHub_dateText <- alt_text_csv %>% - filter(alt_text == "P1_ScotlandHub_dateText") %>% - pull(value) - -P1_ScotlandHub_value <- alt_text_csv %>% - filter(alt_text == "P1_ScotlandHub_value") %>% - pull(value) - - -# 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 - -P2_ScotlandHub_dateText <- alt_text_csv %>% - filter(alt_text == "P2_ScotlandHub_dateText") %>% - pull(value) - -P2_ScotlandHub_value <- alt_text_csv %>% - filter(alt_text == "P2_ScotlandHub_value") %>% - pull(value) - -# P3 ---- -# % 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 <- alt_text_csv %>% - filter(alt_text == "P3_ScotlandHub_dateText") %>% - pull(value) - -P3_ScotlandHub_value <- alt_text_csv %>% - filter(alt_text == "P3_ScotlandHub_value") %>% - pull(value) - - -# P4 ---- -# Number of people with advance statements registered per year with the -# Mental Welfare Commission for Scotland - -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) - - -# E1 ---- -# Number of days people spend in hospital when they are clinically ready to -# be discharged per 1,000 population - -E1_ScotlandHub_dateText <- alt_text_csv %>% - filter(alt_text == "E1_ScotlandHub_dateText") %>% - pull(value) - -E1_ScotlandHub_value <- alt_text_csv %>% - filter(alt_text == "E1_ScotlandHub_value") %>% - pull(value) - - -# EF1 ---- -# Rate of emergency bed days for adults (per 100,000 population) - -EF1_ScotlandHub_dateText <- alt_text_csv %>% - filter(alt_text == "EF1_ScotlandHub_dateText") %>% - pull(value) - -EF1_ScotlandHub_value <- alt_text_csv %>% - filter(alt_text == "EF1_ScotlandHub_value") %>% - pull(value) - - -# EF2 ---- -# % Readmissions to hospital within 28 days of discharge - -EF2_ScotlandHub_dateText <- alt_text_csv %>% - filter(alt_text == "EF2_ScotlandHub_dateText") %>% - pull(value) - -EF2_ScotlandHub_value <- alt_text_csv %>% - filter(alt_text == "EF2_ScotlandHub_value") %>% - pull(value) - - -# EF3 ---- -# Total psychiatric inpatient beds per 100,000 population (NRAC adjusted) - -EF3_ScotlandHub_dateText <- alt_text_csv %>% - filter(alt_text == "EF3_ScotlandHub_dateText") %>% - pull(value) - -EF3_ScotlandHub_value <- alt_text_csv %>% - filter(alt_text == "EF3_ScotlandHub_value") %>% - pull(value) - - -# 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 ---- -# % of did not attend appointments for community based services of people with mental -# health problems - -EF5_ScotlandHub_dateText <- alt_text_csv %>% - filter(alt_text == "EF5_ScotlandHub_dateText") %>% - pull(value) - - -EF5_ScotlandHub_value_low <- alt_text_csv %>% - filter(alt_text == "EF5_ScotlandHub_value_low") %>% - pull(value) - -EF5_ScotlandHub_value_high <- alt_text_csv %>% - filter(alt_text == "EF5_ScotlandHub_value_high") %>% - pull(value) - - -# EQ1 - to work out value ---- -# 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 - not publishing this year ---- -# % 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 <- "(...)" - -#EQ3_ScotlandHub_value <- "..." - - -# 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) - -