Skip to content

Commit

Permalink
Tooltips flags (#38)
Browse files Browse the repository at this point in the history
* Feat: Defined tooltip fn for Trend on LA level page, along with some css styling

* Feat: Applying Trend tooltip to all module pages

* Feat: Improving thr quartile band calculation so is rounded and states the limits of each QB

* Feat: Adding new quartile banding styling to LA mod, switch high polarity so QBs in order

* Tests: Updated build LA stats table tests for new fn

* Feat: Adding tooltip for rank explaining that 1 is always the best performer

* Feat: Added rank tooltip to stat neigh page

* Feat: Added state-funded flag to LA dev app, but decision to not include atm

* Feat: Adding spinner to the LA tables

* Feat: Customising spinners

* Feat: Creating gov style spinner and applying to tables and charts in LA mod

* Feat: Closable notification banner added to create own to point users to GitHub

* Chore: Adding spinner pkg to renv

* Data: Updating BDS, also adding a .csv version og BDS long for public download

* Fix: Adding .. to list of non numeric values in BDS so no warning, updating bar chart

* Feat: Replacing dash with "" for create own missing but due to query, also applied to the download

* Feat: Quartile banding now has white text if coloured background and removed some unecessary code fromLA workshop

* Chore: Removing uneeded columns from BDS long and updating files accordingly (.csv was very large mb)

* Feat: Trialling new rank tooltip content

* Fix: Fixing trend arrow colour issue where no change was appearing red

* Feat: Adding spinner to page header

* Feat: Handling for COVID missing data in charts, currently LA workshop and dev app

* Feat: Functionising covid plotting elements

* Feat: Adding chart type option for covid plot fn

* Feat: Adding covid plotting to bar charts in LA workshop and dev app, adjusting vjust so slightly higher label

* Feat: Added new covid plotting fns to LA mod charts

* Feat: Added new covid plotting fns to Region mod charts

* Feat: Added new covid plotting fns to Stat Neigh mod charts

* Feat: Adding COVID fns to create own, formatting fns and custom-theme to adapt

* Feat: Covid plotting added to create own bar chart - just label

* Feat: Covid plotting added to main scripts

* Feat: Showing covid plot on bar in create own for matching covid lengths

* Feat: Bar chart in create own now has working covid data plot per chart

* Tests: Updating LA charts server test for covid affected indicators and also screenshot for new covid line

* Feat: Combined create own bar chart covid plotting fns

* Feat: Adding roxygen comments for new COVID plotting fns

* Fix: Adding NaN fill to pivot wider in staging so that if two different indicators added in one query it will pick up user created NAs

* Feat: Adding gov spinners to the other page mods (bar Create Own)

* Feat: Adding spinner to Create Own tables and Charts

* Fix: Improving width of the Create Own bar chart so x-axis clearer

* Chore: Adding black dash highlight option to all bar charts

* Tests: Corrected test for new bar chart hover functionality
  • Loading branch information
JT-39 authored Nov 19, 2024
1 parent 5904bf0 commit 3db9701
Show file tree
Hide file tree
Showing 38 changed files with 537,773 additions and 4,724 deletions.
531,931 changes: 531,931 additions & 0 deletions 01_data/02_prod/bds_long.csv

Large diffs are not rendered by default.

Binary file modified 01_data/02_prod/bds_long_0.parquet
Binary file not shown.
315 changes: 155 additions & 160 deletions 02_dev/bds_wide_to_long.qmd
Original file line number Diff line number Diff line change
@@ -1,160 +1,155 @@
---
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"))
```


```{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 for new LAIT",
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}
# Vector to store columns to delete
columns_to_delete <- c(
"Quartile 1 (A)",
"Quartile 2 (B)",
"Quartile 3 (C )",
"Quartile 4 (D)",
"line",
"Data item"
)
# Delete lines in vector from column, remove '.'s and underscores/number
bds_long_clean <- bds_long |>
dplyr::select(!dplyr::all_of(columns_to_delete)) |>
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::mutate(combined_code = paste(`LA Number`, `Short Desc`, Years,
sep = "_"
))
```


```{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 <- readxl::read_xlsx(
path = paste0("01_data/02_prod/LAIT Data Dictionary.xlsx"),
sheet = "Data_prod"
) |>
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"
)
```
---
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"))
```


```{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 <- readxl::read_xlsx(
path = paste0("01_data/02_prod/LAIT Data Dictionary.xlsx"),
sheet = "Data_prod"
) |>
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
)
```
8 changes: 7 additions & 1 deletion 02_dev/create_your_own_page/create_own_table_dev_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ ui <- bslib::page_fillable(

# Main selections ============================================================
h1("Create your own"),
# Full dataset notification banner
full_data_on_github_noti(),
div(
class = "well",
style = "overflow-y: visible; padding: 1rem;",
Expand Down Expand Up @@ -1168,7 +1170,11 @@ server <- function(input, output, session) {
ggiraph::girafe(
ggobj = (bar_chart()),
width_svg = 8.5,
options = generic_ggiraph_options(),
options = generic_ggiraph_options(
opts_hover(
css = "stroke-dasharray:5,5;stroke:black;stroke-width:2px;"
)
),
fonts = list(sans = "Arial")
)
})
Expand Down
8 changes: 6 additions & 2 deletions 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 @@ -24,6 +24,8 @@ ui <- bslib::page_fillable(

# Main selections ============================================================
h1("Create your own"),
# Full dataset notification banner
full_data_on_github_noti(),
div(
class = "well",
style = "overflow-y: visible; padding: 1rem;",
Expand Down Expand Up @@ -130,13 +132,15 @@ server <- function(input, output, session) {
CreateOwnLineChartServer(
"create_own_line",
query_table,
bds_metrics
bds_metrics,
covid_affected_indicators
)

CreateOwnBarChartServer(
"create_own_bar",
query_table,
bds_metrics
bds_metrics,
covid_affected_indicators
)
}

Expand Down
Loading

0 comments on commit 3db9701

Please sign in to comment.