generated from dfe-analytical-services/shiny-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix: Re-adding input synchronisation across pages for LA * Chore: Functionising the filtering of BDS by topic for app inputs, using raw BDS topic indicators to get dupes to appear across topics * Chore: BDS metrics no longer needed in app inputs mod * Feat: Converting Create Your Own inputs to not use topic to filter the BDS, in order to sort URL bookmarking * Chore: Filtering out the discontinued indicators at the point the data dict is loaded in * Feat: For duplicate indicators across topics, combining the topic names in BDS (mainly for Create Your Own table) * Feat: Applying the decoipling of topic column to Create Own table (thus charts), had to update get x-axis fn to deal with multiple labels * Feat: Functionising the dynamic topic label, though leaving out of Create Your Own for now as could have too many topics in label * Chore: Roxgyen comments for dynamic topic label fn * Feat: Updating sever script for new Create Your Own inputs param and removing the topic input from bookmarking * Tests: Updating test fn to remove bds_metrics (no longer needed) * Style: Linting indent corrections * Fix: Topic filtering for dynamic label needs an any() wrapped around the check if topic input is all or empty
- Loading branch information
Showing
15 changed files
with
527 additions
and
490 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,175 +1,176 @@ | ||
--- | ||
title: "LAIT - Shiny upgrade" | ||
subtitle: "Workings and development code" | ||
format: html | ||
date-modified: "`r Sys.Date()`" | ||
output: | ||
html_document: | ||
toc: true | ||
output-file: lait_workings | ||
embed-resources: true | ||
execute: | ||
echo: false | ||
cache: true | ||
message: false | ||
warning: false | ||
--- | ||
|
||
|
||
```{r src-funs} | ||
source(here::here("R/fn_helper_functions.R")) | ||
source(here::here("R/fn_load_data.R")) | ||
``` | ||
|
||
Load the latest Data Dictionary | ||
|
||
```{r write-data_dict} | ||
# Load raw Data Dict from shared folder | ||
data_dict <- readxl::read_xlsx( | ||
path = paste0(shared_folder, "/../Information for App Development/LAIT Data Dictionary (To QA!).xlsx"), | ||
sheet = "Data_prod", | ||
# Replace multi-space with single-space | ||
.name_repair = clean_spaces | ||
) | ||
# Write .csv version | ||
write.csv( | ||
data_dict, | ||
here::here("01_data/02_prod/LAIT Data Dictionary.csv"), | ||
row.names = FALSE | ||
) | ||
``` | ||
|
||
Logic to load BDS wide and convert to long | ||
|
||
```{r pull-latest-bds-data} | ||
# Load raw BDS wide from shared folder | ||
bds_wide_raw_sf <- readxl::read_xlsx( | ||
path = paste0(shared_folder, "/../Information for App Development/BDS - 2024 (JAKE).xlsx"), | ||
sheet = "BDS New", | ||
col_names = TRUE, | ||
skip = 1, | ||
# Replace multi-space with single-space | ||
.name_repair = clean_spaces, | ||
col_types = "text" | ||
) | ||
# Save to data folder | ||
write.csv( | ||
bds_wide_raw_sf, | ||
here::here("01_data/01_raw/BDS_Wide.csv"), | ||
row.names = FALSE | ||
) | ||
``` | ||
|
||
|
||
```{r load-bds} | ||
# Load BDS wide | ||
bds_wide_raw <- read.csv( | ||
here::here("01_data/01_raw/BDS_Wide.csv"), | ||
check.names = FALSE | ||
) | ||
# styler: off | ||
# Remove any cols that are all na | ||
bds_wide <- bds_wide_raw |> | ||
{ \(.) dplyr::select(., dplyr::all_of(non_empty_colnames(.))) }() # nolint: brace | ||
# styler: on | ||
``` | ||
|
||
|
||
```{r wide-long} | ||
# Pivot BDS long on geographic cols | ||
bds_long <- bds_wide |> | ||
tidyr::pivot_longer( | ||
cols = `Barking and Dagenham`:`South West`, | ||
names_to = "LA and Regions", | ||
values_to = "Values" | ||
) |> | ||
# Removes these lines with matching entries in year column | ||
dplyr::filter( | ||
Years %notin% c( | ||
"-", | ||
"", | ||
"Trend", | ||
"Change", | ||
"Rank", | ||
"Target", | ||
"Distance", | ||
"Quartile", | ||
"Deviation National", | ||
"% YoY change", | ||
"%3yr change", | ||
"2010 Target", | ||
"Target 2011", | ||
"NA - Distance", | ||
is.na(0) | ||
) | ||
) | ||
``` | ||
|
||
|
||
```{r bds-clean} | ||
# Delete lines in vector from column, remove '.'s and underscores/number | ||
bds_long_clean <- bds_long |> | ||
dplyr::select(-line) |> | ||
dplyr::mutate( | ||
"LA and Regions" = stringr::str_replace_all(`LA and Regions`, "\\.", " "), | ||
"LA and Regions" = stringr::str_replace_all(`LA and Regions`, " ", "\\. "), | ||
# Remove final _ and following digits | ||
# NOTE: Also remove whitespace - 'LACStableNum_2016on' | ||
`Short Desc` = trimws(sub("_\\d+$", "", `Short Desc`)) | ||
) | ||
``` | ||
|
||
|
||
```{r bds-la_codes} | ||
# Load LA codes | ||
la_codes <- readxl::read_xlsx( | ||
path = here::here("01_data/02_prod/LA code list.xlsx") | ||
) | ||
# Join to bds and create combined codes var | ||
bds_long_la <- bds_long_clean |> | ||
dplyr::left_join(la_codes, by = c("LA and Regions" = "LA Name")) |> | ||
dplyr::select(-Type) | ||
``` | ||
|
||
|
||
```{r bds-data_dict} | ||
# Pull list of measures from data dictionary (primary key and filters for | ||
# only public-safe/in-use measures) | ||
# NOTE: Children_away changed to Children_Away to match BDS | ||
data_dict <- read.csv( | ||
file = paste0("01_data/02_prod/LAIT Data Dictionary.csv"), | ||
check.names = FALSE | ||
) |> | ||
dplyr::mutate(Measure_short = trimws(Measure_short)) |> | ||
dplyr::filter(!grepl("DISCONTINUE", Table_status)) |> | ||
pull_uniques("Measure_short") | ||
# Filter BDS for only measures in the data dict | ||
bds_long_public <- bds_long_la |> | ||
dplyr::filter(`Short Desc` %in% data_dict) | ||
``` | ||
|
||
|
||
```{r bds-save} | ||
# Write out parquet version | ||
arrow::write_dataset( | ||
bds_long_public, | ||
here::here("01_data/02_prod/"), | ||
format = "parquet", | ||
basename_template = "bds_long_{i}.parquet" | ||
) | ||
# Write .csv version (for public use) | ||
write.csv( | ||
bds_long_public, | ||
here::here("01_data/02_prod/bds_long.csv"), | ||
row.names = FALSE | ||
) | ||
``` | ||
--- | ||
title: "LAIT - Shiny upgrade" | ||
subtitle: "Workings and development code" | ||
format: html | ||
date-modified: "`r Sys.Date()`" | ||
output: | ||
html_document: | ||
toc: true | ||
output-file: lait_workings | ||
embed-resources: true | ||
execute: | ||
echo: false | ||
cache: true | ||
message: false | ||
warning: false | ||
--- | ||
|
||
|
||
```{r src-funs} | ||
source(here::here("R/fn_helper_functions.R")) | ||
source(here::here("R/fn_load_data.R")) | ||
``` | ||
|
||
Load the latest Data Dictionary | ||
|
||
```{r write-data_dict} | ||
# Load raw Data Dict from shared folder | ||
data_dict <- readxl::read_xlsx( | ||
path = paste0(shared_folder, "/../Information for App Development/LAIT Data Dictionary (To QA!).xlsx"), | ||
sheet = "Data_prod", | ||
# Replace multi-space with single-space | ||
.name_repair = clean_spaces | ||
) |> | ||
dplyr::filter(!grepl("DISCONTINUE", Table_status)) | ||
# Write .csv version | ||
write.csv( | ||
data_dict, | ||
here::here("01_data/02_prod/LAIT Data Dictionary.csv"), | ||
row.names = FALSE | ||
) | ||
``` | ||
|
||
Logic to load BDS wide and convert to long | ||
|
||
```{r pull-latest-bds-data} | ||
# Load raw BDS wide from shared folder | ||
bds_wide_raw_sf <- readxl::read_xlsx( | ||
path = paste0(shared_folder, "/../Information for App Development/BDS - 2024 (JAKE).xlsx"), | ||
sheet = "BDS New", | ||
col_names = TRUE, | ||
skip = 1, | ||
# Replace multi-space with single-space | ||
.name_repair = clean_spaces, | ||
col_types = "text" | ||
) | ||
# Save to data folder | ||
write.csv( | ||
bds_wide_raw_sf, | ||
here::here("01_data/01_raw/BDS_Wide.csv"), | ||
row.names = FALSE | ||
) | ||
``` | ||
|
||
|
||
```{r load-bds} | ||
# Load BDS wide | ||
bds_wide_raw <- read.csv( | ||
here::here("01_data/01_raw/BDS_Wide.csv"), | ||
check.names = FALSE | ||
) | ||
# styler: off | ||
# Remove any cols that are all na | ||
bds_wide <- bds_wide_raw |> | ||
{ \(.) dplyr::select(., dplyr::all_of(non_empty_colnames(.))) }() # nolint: brace | ||
# styler: on | ||
``` | ||
|
||
|
||
```{r wide-long} | ||
# Pivot BDS long on geographic cols | ||
bds_long <- bds_wide |> | ||
tidyr::pivot_longer( | ||
cols = `Barking and Dagenham`:`South West`, | ||
names_to = "LA and Regions", | ||
values_to = "Values" | ||
) |> | ||
# Removes these lines with matching entries in year column | ||
dplyr::filter( | ||
Years %notin% c( | ||
"-", | ||
"", | ||
"Trend", | ||
"Change", | ||
"Rank", | ||
"Target", | ||
"Distance", | ||
"Quartile", | ||
"Deviation National", | ||
"% YoY change", | ||
"%3yr change", | ||
"2010 Target", | ||
"Target 2011", | ||
"NA - Distance", | ||
is.na(0) | ||
) | ||
) | ||
``` | ||
|
||
|
||
```{r bds-clean} | ||
# Delete lines in vector from column, remove '.'s and underscores/number | ||
bds_long_clean <- bds_long |> | ||
dplyr::select(-line) |> | ||
dplyr::mutate( | ||
"LA and Regions" = stringr::str_replace_all(`LA and Regions`, "\\.", " "), | ||
"LA and Regions" = stringr::str_replace_all(`LA and Regions`, " ", "\\. "), | ||
# Remove final _ and following digits | ||
# NOTE: Also remove whitespace - 'LACStableNum_2016on' | ||
`Short Desc` = trimws(sub("_\\d+$", "", `Short Desc`)) | ||
) | ||
``` | ||
|
||
|
||
```{r bds-la_codes} | ||
# Load LA codes | ||
la_codes <- readxl::read_xlsx( | ||
path = here::here("01_data/02_prod/LA code list.xlsx") | ||
) | ||
# Join to bds and create combined codes var | ||
bds_long_la <- bds_long_clean |> | ||
dplyr::left_join(la_codes, by = c("LA and Regions" = "LA Name")) |> | ||
dplyr::select(-Type) | ||
``` | ||
|
||
|
||
```{r bds-data_dict} | ||
# Pull list of measures from data dictionary (primary key and filters for | ||
# only public-safe/in-use measures) | ||
# NOTE: Children_away changed to Children_Away to match BDS | ||
data_dict <- read.csv( | ||
file = paste0("01_data/02_prod/LAIT Data Dictionary.csv"), | ||
check.names = FALSE | ||
) |> | ||
dplyr::mutate(Measure_short = trimws(Measure_short)) |> | ||
dplyr::filter(!grepl("DISCONTINUE", Table_status)) |> | ||
pull_uniques("Measure_short") | ||
# Filter BDS for only measures in the data dict | ||
bds_long_public <- bds_long_la |> | ||
dplyr::filter(`Short Desc` %in% data_dict) | ||
``` | ||
|
||
|
||
```{r bds-save} | ||
# Write out parquet version | ||
arrow::write_dataset( | ||
bds_long_public, | ||
here::here("01_data/02_prod/"), | ||
format = "parquet", | ||
basename_template = "bds_long_{i}.parquet" | ||
) | ||
# Write .csv version (for public use) | ||
write.csv( | ||
bds_long_public, | ||
here::here("01_data/02_prod/bds_long.csv"), | ||
row.names = FALSE | ||
) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.