Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
db10a68
adds testthat package
tomjemmett Feb 2, 2026
6ce4407
adds tests for app_server
tomjemmett Feb 2, 2026
907789f
adds tests for fct_azure
tomjemmett Feb 2, 2026
3ff6ac5
add tests for mod_pot_age_sex_pyramid
tomjemmett Feb 2, 2026
20a2938
adds tests for mod_plot_nee
tomjemmett Feb 2, 2026
e9c16c0
adds test for app_ui
tomjemmett Feb 2, 2026
edd97cf
add tests for mod_plot_rates_box
tomjemmett Feb 3, 2026
2bbd035
fix test for app_ui
tomjemmett Feb 3, 2026
446577b
add tests for mod_plot_rates_funnel
tomjemmett Feb 3, 2026
d863021
adds tests for mod_plot_rates_trend
tomjemmett Feb 3, 2026
cc3b867
adds tests for mod_select_geography
tomjemmett Feb 3, 2026
851d4aa
adds tests for mod_select_provider
tomjemmett Feb 3, 2026
31a8b62
separates app_ui tests
tomjemmett Feb 3, 2026
b5a7ec1
adds setup script
tomjemmett Feb 3, 2026
8d2b6a3
adds tests for mod_select_strategy
tomjemmett Feb 3, 2026
57e3b43
adds tests for mod_show_strategy_text
tomjemmett Feb 3, 2026
0c0cad7
adds tests for mod_table_diagnoses/procedures
tomjemmett Feb 3, 2026
0ec1656
adds test for run_app
tomjemmett Feb 3, 2026
31f849d
adds tests for utils_data
tomjemmett Feb 4, 2026
a5f385b
adds tests for add_external_resources
tomjemmett Feb 4, 2026
51aef7a
adds tests for utils_plot
tomjemmett Feb 4, 2026
228175c
updates snaps
tomjemmett Feb 4, 2026
75017b9
adds tests for mod_plot_rates
tomjemmett Feb 4, 2026
02b4ecf
remove duplicated function
tomjemmett Feb 4, 2026
5f723d1
adds tests for utils_show_strategy_text/refactors the module
tomjemmett Feb 4, 2026
c030919
add tests for utils_server
tomjemmett Feb 4, 2026
f30da8f
run devtools::document()
tomjemmett Feb 4, 2026
0a9b945
adds tests for utils_table
tomjemmett Feb 4, 2026
1f5316d
fix lint issues
tomjemmett Feb 4, 2026
e7e54f8
adds air configuration to ignore formatting tribbles
tomjemmett Feb 4, 2026
777303c
shifts code from fct_azure to utils_server
tomjemmett Feb 4, 2026
343d13d
adds missing docstrings
tomjemmett Feb 5, 2026
2a4a5ba
adds tests for entable_encounters
tomjemmett Feb 5, 2026
9902b72
adds tests for fct_plots
tomjemmett Feb 5, 2026
7ab6cc8
Apply suggestion from @Copilot
tomjemmett Feb 5, 2026
0a63f55
Apply suggestion from @Copilot
tomjemmett Feb 5, 2026
0d285ae
Apply suggestion from @Copilot
tomjemmett Feb 5, 2026
ff1e17b
switches to session$privateFlush
tomjemmett Feb 5, 2026
cac7b74
run devtools::document
tomjemmett Feb 5, 2026
a0433db
resolve rcmdcheck issues
tomjemmett Feb 5, 2026
d28ec3a
bumps description
tomjemmett Feb 5, 2026
fe836c1
improves fetch_strategy_text tests
tomjemmett Feb 5, 2026
3f5d21d
restructure tests to use helper scripts
tomjemmett Feb 5, 2026
a17cadb
moves library calls to setup.R
tomjemmett Feb 5, 2026
d3f55b7
sets envvar for test
tomjemmett Feb 5, 2026
6b234d7
adds mockery to suggests
tomjemmett Feb 5, 2026
e876682
removes old comment
tomjemmett Feb 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@
^README\.md$
^rsconnect$
^tpma-explorer\.Rproj$
^.cache$
4 changes: 4 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
linters: linters_with_defaults(
line_length_linter(120),
object_length_linter(50)
)
exclusions: list(
"data-raw/la-lookups.R"
)
15 changes: 11 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: tpma.explorer
Title: Explore TPMA Data
Version: 0.2.0.9000
Version: 0.3.4
Authors@R: c(
person("Matt", "Dray", , "matt.dray@nhs.net", role = c("aut", "cre")),
person("Tom", "Jemmett", , "thomas.jemmett@nhs.net", role = "aut")
Expand All @@ -18,6 +18,7 @@ Imports:
AzureStor,
bsicons,
bslib,
cachem,
config,
dplyr,
forcats,
Expand All @@ -26,6 +27,7 @@ Imports:
ggrepel,
glue,
gt,
httr2,
jsonlite,
markdown,
purrr,
Expand All @@ -36,11 +38,16 @@ Imports:
shinycssloaders,
stringr,
tibble,
tidyr,
tidyselect,
withr
tidyr
Remotes:
The-Strategy-Unit/azkit
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.3
Suggests:
mockery,
testthat (>= 3.0.0),
tidyselect,
vdiffr,
withr
Config/testthat/edition: 3
5 changes: 4 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# Generated by roxygen2: do not edit by hand

export(convert_md_to_html)
export(entable_encounters)
export(fetch_strategy_text)
export(generate_rates_baseline_data)
export(get_all_geo_data)
export(get_container)
export(get_golem_config)
export(get_peers_lookup)
export(get_rates_data)
export(get_rates_trend_data)
export(isolate_provider_peers)
export(make_strategy_group_lookup)
export(md_file_to_html)
export(md_string_to_html)
export(plot_age_sex_pyramid)
export(plot_nee)
export(plot_rates_box)
Expand Down
14 changes: 0 additions & 14 deletions R/add_external_resources.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
#' Add External Resources to the Application
#' This function is internally used to add external resources inside the Shiny
#' application.
#' @noRd
add_external_resources <- function() {
shiny::addResourcePath(
"www",
app_sys("app/www")
)
shiny::singleton(
shiny::tags$head()
)
}

#' Access Files in the Current App
#' @param ... Character vectors, specifying subdirectory and file(s)
#' within your package. The default, none, returns the root of the app.
Expand Down
32 changes: 0 additions & 32 deletions R/fct_azure.R

This file was deleted.

86 changes: 24 additions & 62 deletions R/mod_plot_rates.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,77 +35,45 @@ mod_plot_rates_server <- function(
) {
# load static data items
strategies_config <- get_golem_config("mitigators_config")
strategy_group_lookup <- make_strategy_group_lookup(strategies_config)

# return the shiny module
shiny::moduleServer(id, function(input, output, session) {
peers_lookup <- shiny::reactive({
filename <- switch(
selected_geography(),
"nhp" = "nhp-peers.csv",
"la" = "la-peers.csv"
)

shiny::req(filename)

readr::read_csv(
app_sys("app", "data", filename),
col_types = "c"
)
get_peers_lookup(selected_geography())
}) |>
shiny::bindCache(selected_geography())

# Prepare data ----
rates_data <- shiny::reactive({
df <- inputs_data()[["rates"]]

national <- df |>
dplyr::filter(.data$provider == "national") |>
dplyr::select(
"strategy",
"fyear",
national_rate = "std_rate"
)

df |>
dplyr::filter(!.data$provider %in% c("national", "unknown")) |>
dplyr::inner_join(
national,
by = c("strategy", "fyear")
) |>
dplyr::rename(rate = "std_rate") |>
dplyr::select(-"crude_rate")
strategy <- shiny::req(selected_strategy())

get_rates_data(
inputs_data()[["rates"]],
strategy
)
})

rates_trend_data <- shiny::reactive({
shiny::req(rates_data())
shiny::req(selected_provider())
shiny::req(selected_strategy())
df <- shiny::req(rates_data())
provider <- shiny::req(selected_provider())

rates_data() |>
dplyr::filter(
.data$provider == selected_provider(),
.data$strategy == selected_strategy()
) |>
dplyr::arrange(.data$fyear)
get_rates_trend_data(df, provider)
})

rates_baseline_data <- shiny::reactive({
shiny::req(rates_data())
shiny::req(peers_lookup())
shiny::req(selected_provider())
shiny::req(selected_strategy())

provider_peers <- isolate_provider_peers(
selected_provider(),
peers_lookup()
df <- shiny::req(rates_data())
peers_lookup <- shiny::req(peers_lookup())
provider <- shiny::req(selected_provider())
strategy <- shiny::req(selected_strategy())
year <- shiny::req(selected_year())

generate_rates_baseline_data(
df,
provider,
peers_lookup,
year
)
rates_data() |>
generate_rates_baseline_data(
selected_provider(),
provider_peers,
selected_strategy(),
selected_year()
)
})

rates_funnel_calculations <- shiny::reactive({
Expand Down Expand Up @@ -133,15 +101,9 @@ mod_plot_rates_server <- function(
})

strategy_config <- shiny::reactive({
shiny::req(strategies_config)
shiny::req(selected_strategy())

strategy_group_lookup <- strategies_config |> make_strategy_group_lookup()

strategy_group <- strategy_group_lookup |>
dplyr::filter(.data$strategy == selected_strategy()) |>
dplyr::pull("group")
strategy <- shiny::req(selected_strategy())

strategy_group <- strategy_group_lookup[[strategy]]
strategies_config[[strategy_group]]
})

Expand Down
18 changes: 4 additions & 14 deletions R/mod_select_geography.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,18 @@ mod_select_geography_ui <- function(id) {
shiny::selectInput(
ns("geography_select"),
"Filter by geography:",
choices = NULL
choices = c(
"NHS provider trusts" = "nhp",
"Local authorities (LAs)" = "la"
)
)
}

#' Select Geography Server
#' @param id Internal parameter for `shiny`.
#' @noRd
mod_select_geography_server <- function(id) {
geographies <- c(
"NHS provider trusts" = "nhp",
"Local authorities (LAs)" = "la"
)

shiny::moduleServer(id, function(input, output, session) {
shiny::observe({
shiny::req(geographies)
shiny::updateSelectInput(
session,
"geography_select",
choices = geographies
)
})
shiny::reactive(input$geography_select)
})
}
56 changes: 31 additions & 25 deletions R/mod_select_strategy.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,47 +21,53 @@ mod_select_strategy_ui <- function(id) {
)
}

#' Select Strategy Server
#' @param id Internal parameter for `shiny`.
#' Get TPMAs for the drop down menu
#'
#' Reads the mitigators.json file and extracts the name and category (IP/OP/AE).
#'
#' @return A named list of data frames, where the names are the categories (IP/OP/AE)
#' @noRd
mod_select_strategy_server <- function(id) {
# load static data items
mod_select_strategy_get_strategies <- function() {
strategies <- jsonlite::read_json(
app_sys("app", "data", "mitigators.json"),
simplify_vector = TRUE
)

strategies |>
unlist() |>
tibble::enframe("strategy", "name") |>
dplyr::mutate(
category = stringr::str_extract(
.data$name,
"(?<= \\()(IP|OP|AE)(?=-(AA|EF))" # e.g. 'IP' in 'IP-AA-001'
) |>
stringr::str_to_lower()
) |>
dplyr::nest_by(.data$category) |>
tibble::deframe()
}

#' Select Strategy Server
#' @param id Internal parameter for `shiny`.
#' @noRd
mod_select_strategy_server <- function(id) {
# load static data items
strategies <- mod_select_strategy_get_strategies()

# return the shiny module
shiny::moduleServer(id, function(input, output, session) {
shiny::req(strategies)

select_category <- shiny::reactive({
selected_category <- shiny::reactive({
shiny::req(input$strategy_category_select)
input$strategy_category_select
})

shiny::observe({
shiny::req(select_category())
category <- shiny::req(selected_category())

category_strategies <- strategies |>
unlist() |>
tibble::enframe("strategy", "name") |>
dplyr::mutate(
category = stringr::str_extract(
.data$name,
"(?<= \\()(IP|OP|AE)(?=-(AA|EF))" # e.g. 'IP' in 'IP-AA-001'
) |>
stringr::str_to_lower()
) |>
dplyr::filter(.data$category == select_category()) |>
dplyr::select("strategy", "name") |>
strategy_choices <- strategies[[category]] |>
dplyr::select("name", "strategy") |>
tibble::deframe()

strategy_choices <- purrr::set_names(
names(category_strategies),
category_strategies
)

shiny::updateSelectInput(
session,
"strategy_select",
Expand Down
Loading