diff --git a/R/outcome2_page.R b/R/outcome2_page.R index ccb9378..e2c3b37 100644 --- a/R/outcome2_page.R +++ b/R/outcome2_page.R @@ -13,22 +13,86 @@ outcome2_tab <- function(){ div( class = "input_box", style = "min-height:100%; height = 100%; overflow-y: visible", - gov_row( - column( - width = 6, - h2("Inputs go here") + layout_columns( + selectizeInput( + inputId = "select_geography_o2", + label = "Select a geographical level:", + choices = unique(workforce_data %>% pull('geographic_level')), + selected = NULL, + multiple = FALSE, + options = NULL ), - column( - width = 6, - h2("Inputs go here") - ) + conditionalPanel(condition = "input.select_geography_o2 != 'National'", + selectizeInput( + inputId = "geographic_breakdown_o2", + label = "Select a breakdown: ", + choices = NULL, + selected = NULL, + multiple = FALSE, + options = NULL + )), + col_widths = c(4,8) + ), + layout_columns( + conditionalPanel(condition = "input.select_geography_o2 != 'National'", + column( + width = 3, + checkbox_Input( + inputId = "national_comparison_checkbox_o2", + cb_labels = "Compare with National", + checkboxIds = "Yes_national", + label = "", + hint_label = NULL, + small = TRUE + ) + )), + conditionalPanel( + condition = "(input.select_geography_o2 == 'Local authority')", + column( + width = 3, + checkbox_Input( + inputId = "region_comparison_checkbox_o2", + cb_labels = "Compare with Region", + checkboxIds = "Yes_region", + label = "", + hint_label = NULL, + small = TRUE + ) + )), col_widths = c(4,8) ) ) ), + # gov_row( + # div( + # class = "input_box", + # style = "min-height:100%; height = 100%; overflow-y: visible", + # gov_row( + # column( + # width = 6, + # h2("Inputs go here") + # ), + # column( + # width = 6, + # h2("Inputs go here") + # ) + # ) + # ) + # ), br(), gov_row( br(), - h2("Confirmation Sentence"), + p(htmlOutput("outcome2_choice_text1"),htmlOutput("outcome2_choice_text2")), + conditionalPanel( + condition = "(input.geographic_breakdown_o2 == 'Northamptonshire')", + p("To view 2021 and onwards data select ", strong("North Northamptonshire"),"or", strong("West Northamptonshire"),". Northamptonshire local authority was replaced with two new unitary authorities, North Northamptonshire and West Northamptonshire, in April 2021.") ), + conditionalPanel( + condition = "(input.geographic_breakdown_o2 == 'Poole')", + p("To view 2020 and onwards data select ", strong("Bournemouth, Christchurch and Poole"),". Bournemouth, Christchurch and Poole local authority was formed in April 2019.") ), + conditionalPanel( + condition = "(input.geographic_breakdown_o2 == 'Bournemouth')", + p("To view 2020 and onwards data select ", strong("Bournemouth, Christchurch and Poole"),". Bournemouth, Christchurch and Poole local authority was formed in April 2019.") ), + ), + gov_row( br(), div( tabsetPanel( @@ -37,7 +101,138 @@ outcome2_tab <- function(){ tabPanel( "Families engaging and receiving support from their family network", fluidRow( - p("testing") + br() + ), + fluidRow( + column( + width = 6, + value_box( + title = "Percentage of children who cease being looked after due to moving into Special Guardianship Order (SGO)", + value = htmlOutput("SGO_headline_txt") + ) + ), + column( + width = 6, + value_box( + title = "Percentage of children who cease being looked after due to moving into Residence order or Child Arrangement Order (CAO)", + value = htmlOutput("CAO_headline_txt") + ) + ), + br(), + p("Unlocking family networks and kinship carers can be a key source of support where families are experiencing challenges. + Moving children from care arrangements to a SGO or CAO shows that kinship care is being prioritised where children cannot safely live with their parents.") + ), + + accordion( + accordion_panel( + "Percentage of children who cease being looked after due to moving into Special Guardianship Order (SGO)", + gov_row( + h2("Special Guardianship Order (SGO)"), + #p("Unlocking family networks and kinship carers can be a key source of support where families are experiencing challenges. + #Moving children from care arrangements to a SGO or CAO shows that kinship care is being prioritised where children cannot safely live with their parents."), + br(), + plotlyOutput("SGO_time_series"), + br(), + details( + inputId = "tbl_sgo_ceased_cla", + label = "View chart as table", + help_text = ( + dataTableOutput("table_sgo_ceased") + ) + ), + details( + inputId = "sgo_info", + label = "Additional information:", + help_text = ( + p("For more information on the data and definitions, please refer to the", a(href = "https://explore-education-statistics.service.gov.uk/find-statistics/children-looked-after-in-england-including-adoptions/data-guidance", "Children looked after in England including adoptions guidance."), + tags$br(), + "For more information on the methodology, please refer to the", a(href = "https://explore-education-statistics.service.gov.uk/methodology/children-looked-after-in-england-including-adoptions", "Children looked after in England including adoptions methodology."))) + ) + ), + gov_row( + h2("Special Guardianship Order (SGO) by region"), + p("This is a static chart and will not react to geographical level and breakdown selected in the filters at the top. + + The graph represents data from 2023."), + br(), + plotlyOutput("plot_sgo_ceased_reg"), + br(), + details( + inputId = "tbl_sgo_ceased_cla_reg", + label = "View chart as table", + help_text = ( + dataTableOutput("table_sgo_ceased_reg") + ) + ) + ), + gov_row( + h2("Special Guardianship Order (SGO) by local authority"), + p("This chart is reactive to the Local Authority and Regional filters at the top and will not react to the National filter. The chart will display all Local Authorities overall or every Local Authority in the selected Region. + +The graph represents data from 2023."), + br(), + plotlyOutput("plot_SGO_la"), + br(), + details( + inputId = "tbl_sgo_ceased_la", + label = "View chart as table", + help_text = ( + dataTableOutput("table_sgo_la") + ) + ) + ) + ), + accordion_panel( + "Percentage of children who cease being looked after due to moving into Care Arrangement Order (CAO)", + gov_row( + h2("Residence order or Child Arrangement Order (CAO)"), + p("Unlocking family networks and kinship carers can be a key source of support where families are experiencing challenges. + Moving children from care arrangements to a SGO or CAO shows that kinship care is being prioritised where children cannot safely live with their parents."), + br(), + plotlyOutput("CAO_time_series"), + br(), + details( + inputId = "tbl_cao_ceased_cla", + label = "View chart as table", + help_text = ( + dataTableOutput("table_cao_ceased") + ) + ), + ), + gov_row( + h2("Residence order or Child Arrangement Order (CAO) by region"), + p("This is a static chart and will not react to geographical level and breakdown selected in the filters at the top. + + The graph represents data from 2023."), + br(), + plotlyOutput("plot_cao_ceased_reg"), + br(), + details( + inputId = "table_cao_ceased_reg", + label = "View chart as table", + help_text = ( + dataTableOutput("table_cao_ceased_reg") + ) + ), + ), + gov_row( + h2("Residence order or Child Arrangement Order (CAO) by local authority"), + p("This chart is reactive to the Local Authority and Regional filters at the top and will not react to the National filter. The chart will display all Local Authorities overall or every Local Authority in the selected Region. + +The graph represents data from 2023."), + br(), + plotlyOutput("plot_cao_la"), + br(), + details( + inputId = "table_cao_la", + label = "View chart as table", + help_text = ( + dataTableOutput("table_cao_la") + ) + ), + ) + ) + , open = FALSE ) ) ) diff --git a/R/read_data.R b/R/read_data.R index 48cfcc3..50cda1d 100644 --- a/R/read_data.R +++ b/R/read_data.R @@ -538,3 +538,106 @@ read_cin_referral_data <- function(file = "data/c1_children_in_need_referrals_an return(cin_referral_data) } +# Outcome 2 ---- +# read_outcome2 <- function(file = "data/la_children_who_ceased_during_the_year.csv"){ +# ceased_cla_data <- read.csv(file) +# ceased_cla_data <- ceased_cla_data %>% mutate(geo_breakdown = case_when( +# geographic_level == "National" ~ "National",#NA_character_, +# geographic_level == "Regional" ~ region_name, +# geographic_level == "Local authority" ~ la_name +# )) %>% +# mutate(number = case_when( +# number == "z" ~ NA, +# number == "x" ~ NA, +# number == "c" ~ NA, +# TRUE ~ as.numeric(number) +# )) %>% +# select("time_period", "geographic_level","geo_breakdown", "cla_group","characteristic", "number", "percentage") +# } +# read_outcome2 <- function(file = "data/la_children_who_ceased_during_the_year.csv"){ +# ceased_cla_data <- read.csv(file) +# ceased_cla_data <- ceased_cla_data %>% mutate(geo_breakdown = case_when( +# geographic_level == "National" ~ "National",#NA_character_, +# geographic_level == "Regional" ~ region_name, +# geographic_level == "Local authority" ~ la_name +# )) %>% +# mutate(number = case_when( +# number == "z" ~ NA, +# number == "x" ~ NA, +# number == "c" ~ NA, +# TRUE ~ as.numeric(number) +# )) %>% +# select("time_period", "geographic_level","geo_breakdown", "cla_group","characteristic", "number", "percentage") +# +# totals <- ceased_cla_data %>% filter(characteristic == "Total" & cla_group == "Reason episode ceased") %>% +# rename("Total" = "number") %>% +# select(time_period, geographic_level, geo_breakdown, cla_group, Total) +# +# +# test<- ceased_cla_data %>% filter(cla_group == "Reason episode ceased" & characteristic != "Total") +# +# joined <- left_join(test, totals, by = c("time_period", "geographic_level","geo_breakdown", "cla_group")) +# joined$perc <- round((joined$number/joined$Total)*100, digits = 1) +# joined <- joined %>% mutate(perc = case_when( +# percentage == "z" ~ "z", +# percentage == "c" ~ "c", +# percentage == "k" ~ "k", +# percentage == "x" ~ "x", +# TRUE ~ as.character(perc))) %>% mutate(`Percentage ceased %` = case_when( +# percentage == "z" ~ NA, +# percentage == "c" ~ NA, +# percentage == "k" ~ NA, +# percentage == "x" ~ NA, +# TRUE ~ as.numeric(perc) +# )) +# +# return(joined) +# } + +read_outcome2 <- function(file = "data/la_children_who_ceased_during_the_year.csv"){ + ceased_cla_data <- read.csv(file) + old_dorset <- ceased_cla_data %>% filter(time_period <= 2019, new_la_code == "E10000009") + new_dorset <- ceased_cla_data %>% filter(time_period > 2019, new_la_code == "E06000059") + data_without_dorset <- ceased_cla_data %>% filter(la_name != "Dorset") + + dorset_data <- bind_rows(new_dorset, old_dorset) + final_filtered_data <- bind_rows(data_without_dorset, dorset_data) + + ceased_cla_data <- final_filtered_data %>% mutate(geo_breakdown = case_when( + geographic_level == "National" ~ "National",#NA_character_, + geographic_level == "Regional" ~ region_name, + geographic_level == "Local authority" ~ la_name + )) %>% + mutate(number = case_when( + number == "z" ~ NA, + number == "x" ~ NA, + number == "c" ~ NA, + TRUE ~ as.numeric(number) + )) %>% + filter("new_la_code" != "E10000009") %>% + select("time_period", "geographic_level","geo_breakdown", "cla_group","characteristic", "number", "percentage") + + totals <- ceased_cla_data %>% filter(characteristic == "Total" & cla_group == "Reason episode ceased") %>% + rename("Total" = "number") %>% + select(time_period, geographic_level, geo_breakdown, cla_group, Total) + + + test<- ceased_cla_data %>% filter(cla_group == "Reason episode ceased" & characteristic != "Total") + + joined <- left_join(test, totals, by = c("time_period", "geographic_level","geo_breakdown", "cla_group")) + joined$perc <- round((joined$number/joined$Total)*100, digits = 1) + joined <- joined %>% mutate(perc = case_when( + percentage == "z" ~ "z", + percentage == "c" ~ "c", + percentage == "k" ~ "k", + percentage == "x" ~ "x", + TRUE ~ as.character(perc))) %>% mutate(`Ceased (%)` = case_when( + percentage == "z" ~ NA, + percentage == "c" ~ NA, + percentage == "k" ~ NA, + percentage == "x" ~ NA, + TRUE ~ as.numeric(perc) + )) + + return(joined) +} \ No newline at end of file diff --git a/global.R b/global.R index dcd20b2..2f281cd 100644 --- a/global.R +++ b/global.R @@ -130,9 +130,13 @@ combined_cla_data <- merge_cla_dataframes() cin_rates <- read_cin_rate_data() cin_referrals <- read_cin_referral_data() + +#Read in outcome 2 data +ceased_cla_data <- read_outcome2() + #Dropdowns -choice_breakdown_level <- workforce_data %>% select(geographic_level) %>% filter(geographic_level != "National")%>% distinct() -choices_LA <- workforce_data %>% filter(geographic_level == "Local authority") %>% select() +#choice_breakdown_level <- workforce_data %>% select(geographic_level) %>% filter(geographic_level != "National")%>% distinct() +#choices_LA <- workforce_data %>% filter(geographic_level == "Local authority") %>% select() #choices_geographic_level <- dropdown_choices %>% select(geographic_level) %>% distinct() diff --git a/server.R b/server.R index 9b34cf5..e5a6c25 100644 --- a/server.R +++ b/server.R @@ -1881,6 +1881,416 @@ server <- function(input, output, session) { ) }) + #Outcome 2 ----- + # Geographic breakdown o1 (list of either LA names or Region names) + observeEvent(eventExpr={input$select_geography_o2},{ + choices = sort(unique(ceased_cla_data[ceased_cla_data$geographic_level == input$select_geography_o2, "geo_breakdown"]),decreasing = FALSE) + + updateSelectizeInput( + session = session, + inputId = "geographic_breakdown_o2", + selected = choices[1], + choices = choices, + + ) + } + ) + + region_for_la_o2 <- reactive({ + selected_la <- input$geographic_breakdown_o2 + location_data %>% + filter(la_name == selected_la) %>% + pull(region_name) + }) + + output$outcome2_choice_text1 <- renderText({ + if (input$select_geography_o2 == "National") { + paste0("You have selected ", tags$b(input$select_geography_o2), " level statistics on ", tags$b("England"), ".") + } else if (input$select_geography_o2 == "Regional") { + paste0("You have selected ", tags$b(input$select_geography_o2), " level statistics for ", tags$b(input$geographic_breakdown_o2), ".") + } else if (input$select_geography_o2 == "Local authority") { + paste0("You have selected ", tags$b(input$select_geography_o2), " level statistics for ", tags$b(input$geographic_breakdown_o2), ", in ", region_for_la_o2(), ".") + } + }) + + output$outcome2_choice_text2 <- renderText({ + #Checking to see if they picked national average comparison + if (!is.null(input$national_comparison_checkbox_o2) && is.null(input$region_comparison_checkbox_o2)) { + paste0("You have also selected to compare with the ", tags$b("National Average.")) + # If they picked regional comparison + } else if (is.null(input$national_comparison_checkbox_o2) && !is.null(input$region_comparison_checkbox_o2)) { + paste0("You have also selected to compare with the ", tags$b("Regional average.")) + #Picked both national and regional comparison + } else if (!is.null(input$national_comparison_checkbox_o2) && !is.null(input$region_comparison_checkbox_o2)) { + paste0("You have also selected to compare with the ", tags$b("National average"), " and the ", tags$b("Regional average.")) + } + }) + + #Headline stat1 ----- + # output$SGO_headline_txt <- renderText({ + # numerator <- ceased_cla_data %>% filter(time_period == max(ceased_cla_data$time_period) + # & geo_breakdown %in% input$geographic_breakdown_o2 + # & cla_group == "Reason episode ceased" + # & characteristic == "Special guardianship orders") %>% select(number) + # + # denominator <- ceased_cla_data %>% filter(time_period == max(ceased_cla_data$time_period) + # & geo_breakdown %in% input$geographic_breakdown_o2 + # & cla_group == "Reason episode ceased" + # & characteristic == "Total") %>% select(number) + # percent <- (numerator/denominator)*100 + # + # stat <- round(percent, digits = 1) + # paste0(stat,"%","
","

","(",max(ceased_cla_data$time_period),")", "

") + # }) + # + output$SGO_headline_txt <- renderText({ + stat <- ceased_cla_data %>% filter(time_period == max(ceased_cla_data$time_period) + & geo_breakdown %in% input$geographic_breakdown_o2 + & cla_group == "Reason episode ceased" + & characteristic == "Special guardianship orders") %>% select(`Ceased (%)`) + + paste0(stat,"%","
","

","(",max(ceased_cla_data$time_period),")", "

") + }) + + + #Headline stat2 + output$CAO_headline_txt <- renderText({ + stat <- ceased_cla_data %>% filter(time_period == max(ceased_cla_data$time_period) + & geo_breakdown %in% input$geographic_breakdown_o2 + & cla_group == "Reason episode ceased" + & characteristic == "Residence order or child arrangement order granted") %>% select(`Ceased (%)`) + + paste0(stat,"%","
","

","(",max(ceased_cla_data$time_period),")", "

") + }) + + # SGO ---- + #time series and table + output$SGO_time_series <- plotly::renderPlotly({ + validate(need(!is.null(input$select_geography_o2), 'Select a geography level.'), + need(!is.null(input$geographic_breakdown_o2),'Select a breakdown.')) + #not both + if(is.null(input$national_comparison_checkbox_o2) && is.null(input$region_comparison_checkbox_o2)){ + filtered_data<-ceased_cla_data %>% + filter(geographic_level %in% input$select_geography_o2 & geo_breakdown %in% input$geographic_breakdown_o2) %>% + filter(characteristic == "Special guardianship orders") + + #national only + }else if(!is.null(input$national_comparison_checkbox_o2) && is.null(input$region_comparison_checkbox_o2)){ + filtered_data<-ceased_cla_data %>% + filter((geographic_level %in% input$select_geography_o2 & geo_breakdown %in% input$geographic_breakdown_o2)|geographic_level == 'National') %>% + filter(characteristic == "Special guardianship orders") + + #regional only + }else if(is.null(input$national_comparison_checkbox_o2) && !is.null(input$region_comparison_checkbox_o2)){ + location <- location_data %>% + filter(la_name %in% input$geographic_breakdown_o2) + + filtered_data<-ceased_cla_data %>% + filter((geo_breakdown %in% c(input$geographic_breakdown_o2, location$region_name))) %>% + filter(characteristic == "Special guardianship orders") + + #both selected + }else if(!is.null(input$national_comparison_checkbox_o2) && !is.null(input$region_comparison_checkbox_o2)){ + location <- location_data %>% + filter(la_name %in% input$geographic_breakdown_o2) + + filtered_data<- ceased_cla_data %>% + filter((geo_breakdown %in% c(input$geographic_breakdown_o2, location$region_name)|geographic_level == 'National')) %>% + filter(characteristic == "Special guardianship orders") + } + + ggplotly( + plotly_time_series_custom_scale(filtered_data, input$select_geography_o2, input$geographic_breakdown_o2, "Ceased (%)", 'Ceased (%)', 100)%>% + config(displayModeBar = F), + height = 420 + ) + }) + + + output$table_sgo_ceased <- renderDataTable({ + #neither checkboxes + if(is.null(input$national_comparison_checkbox_o2) && is.null(input$region_comparison_checkbox_o2)){ + filtered_data <- ceased_cla_data %>% filter((geo_breakdown %in% input$geographic_breakdown_o2)) %>% + filter(characteristic == "Special guardianship orders") %>% + select(time_period, geo_breakdown, characteristic,number,Total, perc) + + #national only + }else if(!is.null(input$national_comparison_checkbox_o2) && is.null(input$region_comparison_checkbox_o2)){ + filtered_data<-ceased_cla_data %>% + filter((geographic_level %in% input$select_geography_o2 & geo_breakdown %in% input$geographic_breakdown_o2) |geographic_level == 'National')%>% + filter(characteristic == "Special guardianship orders")%>% + select(time_period, geo_breakdown, characteristic,number,Total, perc) + + #regional only + }else if(is.null(input$national_comparison_checkbox_o2) && !is.null(input$region_comparison_checkbox_o2)){ + location <- location_data %>% + filter(la_name %in% input$geographic_breakdown_o2) + + filtered_data<-ceased_cla_data %>% + filter((geo_breakdown %in% c(input$geographic_breakdown_o2, location$region_name))) %>% + filter(characteristic == "Special guardianship orders") %>% + select(time_period, geo_breakdown,characteristic,number,Total,perc) + + #both selected + }else if(!is.null(input$national_comparison_checkbox_o2) && !is.null(input$region_comparison_checkbox_o2)){ + location <- location_data %>% + filter(la_name %in% input$geographic_breakdown_o2) + + filtered_data<- ceased_cla_data %>% + filter((geo_breakdown %in% c(input$geographic_breakdown_o2, location$region_name)|geographic_level == 'National')) %>% + filter(characteristic == "Special guardianship orders") %>% + select(time_period, geo_breakdown,characteristic,number,Total,perc) + } + datatable( + filtered_data, + colnames = c("Time period", "Geographical breakdown","Characteristic","Number", "Total", "Ceased (%)"), + options = list( + scrollx = FALSE, + paging = TRUE + ) + ) + }) + ## + #SGO by region ----- + + output$plot_sgo_ceased_reg <- plotly::renderPlotly({ + data <- ceased_cla_data %>% filter(characteristic == "Special guardianship orders") + + ggplotly( + by_region_bar_plot(data, "Ceased (%)","Ceased (%)")%>% + config(displayModeBar = F), + height = 420 + ) + }) + + #turnover rate by region table + output$table_sgo_ceased_reg <- renderDataTable({ + datatable( + ceased_cla_data %>% filter(geographic_level == 'Regional', time_period == max(ceased_cla_data$time_period)) %>% + filter(characteristic == "Special guardianship orders") %>% + select(time_period, geo_breakdown,characteristic, perc) %>% + arrange(desc(perc)), + colnames = c("Time period", "Geographical breakdown", "Characteristic", "Ceased (%)"), + options = list( + scrollx = FALSE, + paging = TRUE + ) + ) + }) + + ## + #SGO by la ---- + output$plot_SGO_la <- plotly::renderPlotly({ + data <- ceased_cla_data %>% filter(characteristic == "Special guardianship orders") + ggplotly( + by_la_bar_plot(data, input$geographic_breakdown_o2, input$select_geography_o2, 'Ceased (%)', 'Ceased (%)') %>% + config(displayModeBar = F), + height = 420 + ) + }) + + #Special Guardianship orders by LA table + output$table_sgo_la <- renderDataTable({ + if (input$select_geography_o2 == "Regional") { + if (input$geographic_breakdown_o2 == "London") { + # Include both Inner London and Outer London + location <- location_data %>% + filter(region_name %in% c("Inner London", "Outer London")) %>% + pull(la_name) + } else { + # Get the la_name values within the selected region_name + location <- location_data %>% + filter(region_name == input$geographic_breakdown_o2) %>% + pull(la_name) + } + + data <- ceased_cla_data %>% + filter(geo_breakdown %in% location, time_period == max(time_period)) %>% + filter(characteristic == "Special guardianship orders") %>% + select(time_period, geo_breakdown, characteristic, perc) %>% + arrange(desc(perc)) + + } else if (input$select_geography_e2 %in% c("Local authority", "National")) { + data <- ceased_cla_data %>% filter(geographic_level == 'Local authority', time_period == max(ceased_cla_data$time_period)) %>% + filter(characteristic == "Special guardianship orders") %>% + select(time_period, geo_breakdown, characteristic, perc) %>% + arrange(desc(perc)) + } + + datatable( + data, + colnames = c("Time period", "Geographical breakdown", "Characteristic", "Ceased (%)"), + options = list( + scrollx = FALSE, + paging = TRUE + ) + ) + }) + + + + # CAO ---- + #time series and table + output$CAO_time_series <- plotly::renderPlotly({ + validate(need(!is.null(input$select_geography_o2), 'Select a geography level.'), + need(!is.null(input$geographic_breakdown_o2),'Select a breakdown.')) + #not both + if(is.null(input$national_comparison_checkbox_o2) && is.null(input$region_comparison_checkbox_o2)){ + filtered_data<-ceased_cla_data %>% + filter(geographic_level %in% input$select_geography_o2 & geo_breakdown %in% input$geographic_breakdown_o2) %>% + filter(characteristic == "Residence order or child arrangement order granted") + + #national only + }else if(!is.null(input$national_comparison_checkbox_o2) && is.null(input$region_comparison_checkbox_o2)){ + filtered_data<-ceased_cla_data %>% + filter((geographic_level %in% input$select_geography_o2 & geo_breakdown %in% input$geographic_breakdown_o2)|geographic_level == 'National') %>% + filter(characteristic == "Residence order or child arrangement order granted") + + #regional only + }else if(is.null(input$national_comparison_checkbox_o2) && !is.null(input$region_comparison_checkbox_o2)){ + location <- location_data %>% + filter(la_name %in% input$geographic_breakdown_o2) + + filtered_data<-ceased_cla_data %>% + filter((geo_breakdown %in% c(input$geographic_breakdown_o2, location$region_name))) %>% + filter(characteristic == "Residence order or child arrangement order granted") + + #both selected + }else if(!is.null(input$national_comparison_checkbox_o2) && !is.null(input$region_comparison_checkbox_o2)){ + location <- location_data %>% + filter(la_name %in% input$geographic_breakdown_o2) + + filtered_data<- ceased_cla_data %>% + filter((geo_breakdown %in% c(input$geographic_breakdown_o2, location$region_name)|geographic_level == 'National')) %>% + filter(characteristic == "Residence order or child arrangement order granted") + } + + ggplotly( + plotly_time_series_custom_scale(filtered_data, input$select_geography_o2, input$geographic_breakdown_o2, "Ceased (%)", 'Ceased (%)', 100)%>% + config(displayModeBar = F), + height = 420 + ) + }) + + + output$table_cao_ceased <- renderDataTable({ + #neither checkboxes + if(is.null(input$national_comparison_checkbox_o2) && is.null(input$region_comparison_checkbox_o2)){ + filtered_data <- ceased_cla_data %>% filter((geo_breakdown %in% input$geographic_breakdown_o2)) %>% + filter(characteristic == "Residence order or child arrangement order granted") %>% + select(time_period, geo_breakdown, characteristic, number, Total, perc) + + #national only + }else if(!is.null(input$national_comparison_checkbox_o2) && is.null(input$region_comparison_checkbox_o2)){ + filtered_data<-ceased_cla_data %>% + filter((geographic_level %in% input$select_geography_o2 & geo_breakdown %in% input$geographic_breakdown_o2) |geographic_level == 'National') %>% + filter(characteristic == "Residence order or child arrangement order granted")%>% + select(time_period, geo_breakdown, characteristic, number, Total, perc) + + #regional only + }else if(is.null(input$national_comparison_checkbox_o2) && !is.null(input$region_comparison_checkbox_o2)){ + location <- location_data %>% + filter(la_name %in% input$geographic_breakdown_o2) + + filtered_data<-ceased_cla_data %>% + filter((geo_breakdown %in% c(input$geographic_breakdown_o2, location$region_name))) %>% + filter(characteristic == "Residence order or child arrangement order granted") %>% + select(time_period, geo_breakdown,characteristic,number, Total, perc) + + #both selected + }else if(!is.null(input$national_comparison_checkbox_o2) && !is.null(input$region_comparison_checkbox_o2)){ + location <- location_data %>% + filter(la_name %in% input$geographic_breakdown_o2) + + filtered_data<- ceased_cla_data %>% + filter((geo_breakdown %in% c(input$geographic_breakdown_o2, location$region_name)|geographic_level == 'National')) %>% + filter(characteristic == "Residence order or child arrangement order granted") %>% + select(time_period, geo_breakdown,characteristic,number, Total, perc) + } + datatable( + filtered_data, + colnames = c("Time period", "Geographical breakdown","Characteristic","Number", "Total", "Ceased (%)"), + options = list( + scrollx = FALSE, + paging = TRUE + ) + ) + }) + + #by region + output$plot_cao_ceased_reg <- plotly::renderPlotly({ + data <- ceased_cla_data %>% filter(characteristic == "Residence order or child arrangement order granted") + + ggplotly( + by_region_bar_plot(data, "Ceased (%)", "Ceased (%)")%>% + config(displayModeBar = F), + height = 420 + ) + }) + + #turnover rate by region table + output$table_cao_ceased_reg <- renderDataTable({ + datatable( + ceased_cla_data %>% filter(geographic_level == 'Regional', time_period == max(ceased_cla_data$time_period)) %>% + filter(characteristic == "Residence order or child arrangement order granted") %>% + select(time_period, geo_breakdown, characteristic, perc) %>% + arrange(desc(perc)), + colnames = c("Time period", "Geographical breakdown", "Characteristic", "Ceased (%)"), + options = list( + scrollx = FALSE, + paging = TRUE + ) + ) + }) + + #by la + output$plot_cao_la <- plotly::renderPlotly({ + data <- ceased_cla_data %>% filter(characteristic == "Residence order or child arrangement order granted") + ggplotly( + by_la_bar_plot(data, input$geographic_breakdown_o2, input$select_geography_o2, 'Ceased (%)', 'Ceased (%)') %>% + config(displayModeBar = F), + height = 420 + ) + }) + + #CAO by LA table + output$table_cao_la <- renderDataTable({ + if (input$select_geography_o2 == "Regional") { + if (input$geographic_breakdown_o2 == "London") { + # Include both Inner London and Outer London + location <- location_data %>% + filter(region_name %in% c("Inner London", "Outer London")) %>% + pull(la_name) + } else { + # Get the la_name values within the selected region_name + location <- location_data %>% + filter(region_name == input$geographic_breakdown_o2) %>% + pull(la_name) + } + + data <- ceased_cla_data %>% + filter(geo_breakdown %in% location, time_period == max(time_period)) %>% + filter(characteristic == "Residence order or child arrangement order granted") %>% + select(time_period, geo_breakdown, characteristic, perc) %>% + arrange(desc(perc)) + + } else if (input$select_geography_e2 %in% c("Local authority", "National")) { + data <- ceased_cla_data %>% filter(geographic_level == 'Local authority', time_period == max(ceased_cla_data$time_period)) %>% + filter(characteristic == "Residence order or child arrangement order granted") %>% + select(time_period, geo_breakdown, characteristic, perc) %>% + arrange(desc(perc)) + } + + datatable( + data, + colnames = c("Time period", "Geographical breakdown", "Characteristic", "Ceased (%)"), + options = list( + scrollx = FALSE, + paging = TRUE + ) + ) + }) + # Don't touch the code below ----------------------- observeEvent(input$go, { diff --git a/ui.R b/ui.R index 0a697c9..4433388 100644 --- a/ui.R +++ b/ui.R @@ -125,7 +125,7 @@ ui <- function(input, output, session) { introductionPanel(), #dashboard_panel(), outcome1_tab(), - #outcome2_tab(), + outcome2_tab(), #outcome3_tab(), #outcome4_tab(), enabler1_tab(), diff --git a/www/dfe_shiny_gov_style.css b/www/dfe_shiny_gov_style.css index 273adca..a589918 100644 --- a/www/dfe_shiny_gov_style.css +++ b/www/dfe_shiny_gov_style.css @@ -580,7 +580,7 @@ btn is the user guide button } /* Hide the last page on the navlist bar (user guide page)*/ -#navlistPanel > li:nth-child(8) { +#navlistPanel > li:nth-child(9) { display: none; }