Skip to content

Commit

Permalink
Create own inputs (#45)
Browse files Browse the repository at this point in the history
* 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
JT-39 authored Nov 26, 2024
1 parent ea9706e commit 1483438
Show file tree
Hide file tree
Showing 15 changed files with 527 additions and 490 deletions.
39 changes: 0 additions & 39 deletions 01_data/02_prod/LAIT Data Dictionary.csv

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion 02_dev/all_la_page/all_la_dev_app_mod.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ server_mod <- function(input, output, session) {
app_inputs <- appInputsServer(
"all_la_inputs",
shared_values,
bds_metrics,
topic_indicator_full
)

Expand Down
351 changes: 176 additions & 175 deletions 02_dev/bds_wide_to_long.qmd
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
)
```
5 changes: 4 additions & 1 deletion 02_dev/create_your_own_page/create_own_table_dev_mod_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ ui <- bslib::page_fillable(
# Main App Server
server <- function(input, output, session) {
# Call the main inputs module
create_inputs <- Create_MainInputsServer("create_inputs", bds_metrics)
create_inputs <- Create_MainInputsServer(
"create_inputs",
topic_indicator_full
)

# Year range
year_input <- YearRangeServer(
Expand Down
1 change: 0 additions & 1 deletion 02_dev/la_level_page/la_dev_app_mod.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ server_mod <- function(input, output, session) {
app_inputs <- appInputsServer(
"la_inputs",
shared_values,
bds_metrics,
metrics_raw
)

Expand Down
Loading

0 comments on commit 1483438

Please sign in to comment.