Skip to content

Commit

Permalink
Added numbers aswell as rate to CLA tables
Browse files Browse the repository at this point in the history
  • Loading branch information
PATERSON authored and PATERSON committed Mar 22, 2024
1 parent a6ec947 commit 6f212cd
Showing 1 changed file with 35 additions and 29 deletions.
64 changes: 35 additions & 29 deletions server.R
Original file line number Diff line number Diff line change
Expand Up @@ -1295,13 +1295,13 @@ server <- function(input, output, session) {
if (is.null(input$national_comparison_checkbox_o1) && is.null(input$region_comparison_checkbox_o1)) {
filtered_data <- cla_rates %>%
filter(geo_breakdown %in% input$geographic_breakdown_o1) %>%
select(time_period, geo_breakdown, rate_per_10000, population_count)
select(time_period, geo_breakdown, number, rate_per_10000, population_count)

# national only
} else if (!is.null(input$national_comparison_checkbox_o1) && is.null(input$region_comparison_checkbox_o1)) {
filtered_data <- cla_rates %>%
filter((geographic_level %in% input$select_geography_o1 & geo_breakdown %in% input$geographic_breakdown_o1) | geographic_level == "National") %>%
select(time_period, geo_breakdown, rate_per_10000, population_count)
select(time_period, geo_breakdown, number, rate_per_10000, population_count)

# regional only
} else if (is.null(input$national_comparison_checkbox_o1) && !is.null(input$region_comparison_checkbox_o1)) {
Expand All @@ -1310,7 +1310,7 @@ server <- function(input, output, session) {

filtered_data <- cla_rates %>%
filter((geo_breakdown %in% c(input$geographic_breakdown_o1, location$region_name))) %>%
select(time_period, geo_breakdown, rate_per_10000, population_count)
select(time_period, geo_breakdown, number, rate_per_10000, population_count)

# both selected
} else if (!is.null(input$national_comparison_checkbox_o1) && !is.null(input$region_comparison_checkbox_o1)) {
Expand All @@ -1319,14 +1319,14 @@ server <- function(input, output, session) {

filtered_data <- cla_rates %>%
filter((geo_breakdown %in% c(input$geographic_breakdown_o1, location$region_name) | geographic_level == "National")) %>%
select(time_period, geo_breakdown, rate_per_10000, population_count)
select(time_period, geo_breakdown, number, rate_per_10000, population_count)
}

datatable(
filtered_data %>%
filter(population_count == "Children starting to be looked after each year") %>%
select(time_period, geo_breakdown, rate_per_10000),
colnames = c("Time period", "Geographical breakdown", "Rate of children starting in care, per 10,000"),
select(time_period, geo_breakdown, number, rate_per_10000),
colnames = c("Time period", "Geographical breakdown", "Number of children starting in care", "Rate of children starting in care, per 10,000"),
options = list(
scrollx = FALSE,
paging = TRUE
Expand Down Expand Up @@ -1356,10 +1356,10 @@ server <- function(input, output, session) {
datatable(
cla_rates %>% filter(geographic_level == "Regional", time_period == max(cla_rates$time_period), population_count == "Children starting to be looked after each year") %>% select(
time_period, geo_breakdown,
rate_per_10000
number, rate_per_10000
) %>%
arrange(desc(rate_per_10000)),
colnames = c("Time period", "Geographical breakdown", "Rate of children starting in care, per 10,000"),
colnames = c("Time period", "Geographical breakdown", "Number of children starting in care", "Rate of children starting in care, per 10,000"),
options = list(
scrollx = FALSE,
paging = TRUE
Expand Down Expand Up @@ -1401,21 +1401,21 @@ server <- function(input, output, session) {

data <- cla_rates %>%
filter(geo_breakdown %in% location, time_period == max(time_period), population_count == "Children starting to be looked after each year") %>%
select(time_period, geo_breakdown, rate_per_10000) %>%
select(time_period, geo_breakdown, number, rate_per_10000) %>%
arrange(desc(rate_per_10000))
} else if (input$select_geography_o1 %in% c("Local authority", "National")) {
data <- cla_rates %>%
filter(geographic_level == "Local authority", time_period == max(cla_rates$time_period), population_count == "Children starting to be looked after each year") %>%
select(
time_period, geo_breakdown,
rate_per_10000
number, rate_per_10000
) %>%
arrange(desc(rate_per_10000))
}

datatable(
data,
colnames = c("Time period", "Geographical breakdown", "Rate of children starting in care, per 10,000"),
colnames = c("Time period", "Geographical breakdown", "Number of children starting in care", "Rate of children starting in care, per 10,000"),
options = list(
scrollx = FALSE,
paging = TRUE
Expand Down Expand Up @@ -1824,6 +1824,7 @@ server <- function(input, output, session) {
)
})

# UASC chart
output$plot_uasc <- plotly::renderPlotly({
shiny::validate(
need(input$select_geography_o1 != "", "Select a geography level."),
Expand All @@ -1836,6 +1837,7 @@ server <- function(input, output, session) {
)
})

# UASC table
output$table_uasc <- renderDataTable({
shiny::validate(
need(input$select_geography_o1 != "", "Select a geography level."),
Expand All @@ -1848,9 +1850,9 @@ server <- function(input, output, session) {
characteristic %in% c("Unaccompanied asylum-seeking children", "Non-unaccompanied asylum-seeking children"),
population_count == "Children starting to be looked after each year"
) %>%
select(time_period, geo_breakdown, placement_per_10000, characteristic) %>%
select(time_period, geo_breakdown, characteristic, placements_number, placement_per_10000) %>%
arrange(desc(time_period)),
colnames = c("Time period", "Geographical breakdown", "Rate per 10,000 children", "UASC status"),
colnames = c("Time period", "Geographical breakdown", "UASC status", "Number of children starting in care", "Rate per 10,000 children"),
options = list(
scrollx = FALSE,
paging = TRUE,
Expand All @@ -1859,6 +1861,7 @@ server <- function(input, output, session) {
)
})

# UASC chart by region
output$plot_uasc_reg <- plotly::renderPlotly({
shiny::validate(
need(input$select_geography_o1 != "", "Select a geography level."),
Expand All @@ -1871,6 +1874,7 @@ server <- function(input, output, session) {
)
})

# UASC table by region
output$table_uasc_reg <- renderDataTable({
shiny::validate(
need(input$select_geography_o1 != "", "Select a geography level."),
Expand All @@ -1882,15 +1886,16 @@ server <- function(input, output, session) {
population_count == "Children starting to be looked after each year",
time_period == max(time_period)
) %>%
select(time_period, geo_breakdown, placement_per_10000, characteristic),
colnames = c("Time period", "Geographical breakdown", "Rate per 10,000 children", "UASC status"),
select(time_period, geo_breakdown, characteristic, placements_number, placement_per_10000),
colnames = c("Time period", "Geographical breakdown", "UASC status", "Number of children starting in care", "Rate per 10,000 children"),
options = list(
scrollx = FALSE,
paging = TRUE
)
)
})

# UASC plot by LA
output$plot_uasc_la <- plotly::renderPlotly({
shiny::validate(
need(input$select_geography_o1 != "", "Select a geography level."),
Expand All @@ -1903,6 +1908,7 @@ server <- function(input, output, session) {
)
})

# UASC table by LA
output$table_uasc_la <- renderDataTable({
shiny::validate(
need(input$select_geography_o1 != "", "Select a geography level."),
Expand All @@ -1926,21 +1932,21 @@ server <- function(input, output, session) {
geo_breakdown %in% location, time_period == max(combined_cla_data$time_period), characteristic %in% c("Unaccompanied asylum-seeking children", "Non-unaccompanied asylum-seeking children"),
population_count == "Children starting to be looked after each year",
) %>%
select(time_period, geo_breakdown, placement_per_10000, characteristic) %>%
select(time_period, geo_breakdown, characteristic, placements_number, placement_per_10000) %>%
arrange(desc(placement_per_10000))
} else if (input$select_geography_o1 %in% c("Local authority", "National")) {
data <- combined_cla_data %>%
filter(
geographic_level == "Local authority", time_period == max(combined_cla_data$time_period), characteristic %in% c("Unaccompanied asylum-seeking children", "Non-unaccompanied asylum-seeking children"),
population_count == "Children starting to be looked after each year",
) %>%
select(time_period, geo_breakdown, placement_per_10000, characteristic) %>%
select(time_period, geo_breakdown, characteristic, placements_number, placement_per_10000) %>%
arrange(desc(placement_per_10000))
}

datatable(
data,
colnames = c("Time period", "Geographical breakdown", "Rate per 10,000 children", "UASC status"),
colnames = c("Time period", "Geographical breakdown", "UASC status", "Number of children starting in care", "Rate per 10,000 children"),
options = list(
scrollx = FALSE,
paging = TRUE
Expand Down Expand Up @@ -2008,13 +2014,13 @@ server <- function(input, output, session) {
if (is.null(input$national_comparison_checkbox_o1) && is.null(input$region_comparison_checkbox_o1)) {
filtered_data <- cla_rates %>%
filter(geo_breakdown %in% input$geographic_breakdown_o1) %>%
select(time_period, geo_breakdown, rate_per_10000, population_count)
select(time_period, geo_breakdown, number, rate_per_10000, population_count)

# national only
} else if (!is.null(input$national_comparison_checkbox_o1) && is.null(input$region_comparison_checkbox_o1)) {
filtered_data <- cla_rates %>%
filter((geographic_level %in% input$select_geography_o1 & geo_breakdown %in% input$geographic_breakdown_o1) | geographic_level == "National") %>%
select(time_period, geo_breakdown, rate_per_10000, population_count)
select(time_period, geo_breakdown, number, rate_per_10000, population_count)

# regional only
} else if (is.null(input$national_comparison_checkbox_o1) && !is.null(input$region_comparison_checkbox_o1)) {
Expand All @@ -2023,7 +2029,7 @@ server <- function(input, output, session) {

filtered_data <- cla_rates %>%
filter((geo_breakdown %in% c(input$geographic_breakdown_o1, location$region_name))) %>%
select(time_period, geo_breakdown, rate_per_10000, population_count)
select(time_period, geo_breakdown, number, rate_per_10000, population_count)

# both selected
} else if (!is.null(input$national_comparison_checkbox_o1) && !is.null(input$region_comparison_checkbox_o1)) {
Expand All @@ -2032,14 +2038,14 @@ server <- function(input, output, session) {

filtered_data <- cla_rates %>%
filter((geo_breakdown %in% c(input$geographic_breakdown_o1, location$region_name) | geographic_level == "National")) %>%
select(time_period, geo_breakdown, rate_per_10000, population_count)
select(time_period, geo_breakdown, number, rate_per_10000, population_count)
}

datatable(
filtered_data %>%
filter(population_count == "Children looked after at 31 March each year") %>%
select(time_period, geo_breakdown, rate_per_10000),
colnames = c("Time period", "Geographical breakdown", "Rate per 10,000 children"),
select(time_period, geo_breakdown, number, rate_per_10000),
colnames = c("Time period", "Geographical breakdown", "Number of children looked after on 31 March", "Rate per 10,000 children"),
options = list(
scrollx = FALSE,
paging = TRUE
Expand Down Expand Up @@ -2069,10 +2075,10 @@ server <- function(input, output, session) {
datatable(
cla_rates %>% filter(geographic_level == "Regional", time_period == max(cla_rates$time_period), population_count == "Children looked after at 31 March each year") %>% select(
time_period, geo_breakdown,
rate_per_10000
number, rate_per_10000
) %>%
arrange(desc(rate_per_10000)),
colnames = c("Time period", "Geographical breakdown", "Rate per 10,000 children"),
colnames = c("Time period", "Geographical breakdown", "Number of children looked after on 31 March", "Rate per 10,000 children"),
options = list(
scrollx = FALSE,
paging = TRUE
Expand Down Expand Up @@ -2114,21 +2120,21 @@ server <- function(input, output, session) {

data <- cla_rates %>%
filter(geo_breakdown %in% location, time_period == max(time_period), population_count == "Children looked after at 31 March each year") %>%
select(time_period, geo_breakdown, rate_per_10000) %>%
select(time_period, geo_breakdown, number, rate_per_10000) %>%
arrange(desc(rate_per_10000))
} else if (input$select_geography_o1 %in% c("Local authority", "National")) {
data <- cla_rates %>%
filter(geographic_level == "Local authority", time_period == max(cla_rates$time_period), population_count == "Children looked after at 31 March each year") %>%
select(
time_period, geo_breakdown,
rate_per_10000
number, rate_per_10000
) %>%
arrange(desc(rate_per_10000))
}

datatable(
data,
colnames = c("Time period", "Geographical breakdown", "Rate per 10,000 children"),
colnames = c("Time period", "Geographical breakdown", "Number of children looked after on 31 March", "Rate per 10,000 children"),
options = list(
scrollx = FALSE,
paging = TRUE
Expand Down

0 comments on commit 6f212cd

Please sign in to comment.