Skip to content

Commit

Permalink
Feat: Download option now avaiable for Stat neigh tables
Browse files Browse the repository at this point in the history
  • Loading branch information
JT-39 committed Oct 17, 2024
1 parent bf2ccb7 commit 36d05ce
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 35 deletions.
23 changes: 4 additions & 19 deletions 02_dev/stat_n_level_page/stat_n_dev_app_mod.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,7 @@ ui_mod <- bslib::page_fillable(
appInputsUI("stat_n_inputs"),

# Region tables =============================================================
div(
class = "well",
style = "overflow-y: visible;",
bslib::card(
bslib::card_header("Statistical Neighbours"),
# Statistical Neighbour LA SNs Table ----------------------------------
StatN_LASNsTableUI("stat_n_sns_table"),
# Statistical Neighbour LA Geog Compare Table -------------------------
StatN_GeogCompTableUI("stat_n_comp_table")
)
),
div(
class = "well",
# Statistical Neighbour Statistics Table ------------------------------
StatN_StatsTableUI("stat_n_stats_table")
),
StatN_TablesUI("stat_n_tables"),
div(
class = "well",
style = "overflow-y: visible;",
Expand Down Expand Up @@ -74,23 +59,23 @@ server_mod <- function(input, output, session) {
# Statistical Neighbour tables ==============================================
# LA statistical neighbours table -------------------------------------------
StatN_LASNsTableServer(
"stat_n_sns_table",
"stat_n_tables",
app_inputs,
bds_metrics,
stat_n_la
)

# LA geographic comparison table --------------------------------------------
StatN_GeogCompTableServer(
"stat_n_comp_table",
"stat_n_tables",
app_inputs,
bds_metrics,
stat_n_la
)

# Statistics Table ----------------------------------------------------------
StatN_StatsTableServer(
"stat_n_stats_table",
"stat_n_stats_mod",
app_inputs,
bds_metrics,
stat_n_la,
Expand Down
81 changes: 65 additions & 16 deletions R/lait_modules/mod_stat_n_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,40 @@ StatN_DataServer <- function(id, la_input, filtered_bds, stat_n_la) {
#' @return A UI component containing a reactable output for displaying the
#' statistical neighbour table.
#'
StatN_LASNsTableUI <- function(id) {
StatN_TablesUI <- function(id) {
ns <- NS(id)

reactable::reactableOutput(ns("output_table"))
div(
class = "well",
style = "overflow-y: visible;",
bslib::navset_tab(
id = "stat_n_tables_tabs",
bslib::nav_panel(
"Tables",
bslib::card(
# Statistical Neighbour LA SNs Table --------------------------------
bslib::card_header("Statistical Neighbours"),
reactable::reactableOutput(ns("statn_table")),
# Statistical Neighbour LA Geog Compare Table -----------------------
div(
# Add black border between the tables
style = "overflow-y: visible;border-top: 2px solid black; padding-top: 2.5rem;",
bslib::card_header("Other Geographies"),
reactable::reactableOutput(ns("geog_table"))
)
),
br(),
# Statistical Neighbour Statistics Table ------------------------------
StatN_StatsTableUI("stat_n_stats_mod")
),
bslib::nav_panel(
"Download",
file_type_input_btn(ns("file_type")),
Download_DataUI(ns("statn_download"), "Statistical Neighbour Table"),
Download_DataUI(ns("geog_download"), "Other Geographies Table")
)
)
)
}


Expand Down Expand Up @@ -301,26 +331,36 @@ StatN_LASNsTableServer <- function(id,
# Current year
current_year <- Current_YearServer("current_year", stat_n_table, "wide")

# Table output
output$output_table <- reactable::renderReactable({
# Filter to LA and SNs
stat_n_sns_table <- stat_n_table() |>
# Filter for selected LA and its SNs - ready for table output
stat_n_sns_table <- reactive({
stat_n_table() |>
dplyr::filter(`LA and Regions` %in% c(app_inputs$la(), stat_n_sns())) |>
dplyr::arrange(.data[[current_year()]], `LA and Regions`)
})

# Download ----------------------------------------------------------------
Download_DataServer(
"statn_download",
reactive(input$file_type),
reactive(stat_n_sns_table()),
reactive(c(app_inputs$la(), app_inputs$indicator(), "SN-Stat-Neighbour-Level"))
)

# Table output ------------------------------------------------------------
output$statn_table <- reactable::renderReactable({
# Create table with correct formatting
dfe_reactable(
stat_n_sns_table,
stat_n_sns_table(),
columns = utils::modifyList(
format_num_reactable_cols(
stat_n_sns_table,
stat_n_sns_table(),
get_indicator_dps(filtered_bds()),
num_exclude = "LA Number"
),
set_custom_default_col_widths()
),
rowStyle = function(index) {
highlight_selected_row(index, stat_n_sns_table, app_inputs$la())
highlight_selected_row(index, stat_n_sns_table(), app_inputs$la())
},
pagination = FALSE
)
Expand Down Expand Up @@ -403,24 +443,34 @@ StatN_GeogCompTableServer <- function(id,
stat_n_la
)

# Table output
output$output_table <- reactable::renderReactable({
# Keep LA geographic comparison areas
stat_n_comp_table <- stat_n_table() |>
# Keep LA geographic comparison areas
stat_n_geog_table <- reactive({
stat_n_table() |>
dplyr::filter(`LA and Regions` %in% c(
"Statistical Neighbours",
stat_n_region(),
"England"
)) |>
dplyr::arrange(`LA and Regions`)
})

# Download ----------------------------------------------------------------
Download_DataServer(
"geog_download",
reactive(input$file_type),
reactive(stat_n_geog_table()),
reactive(c(app_inputs$la(), app_inputs$indicator(), "Geog-Stat-Neighbour-Level"))
)

# Table output ------------------------------------------------------------
output$geog_table <- reactable::renderReactable({
# Output table
dfe_reactable(
stat_n_comp_table,
stat_n_geog_table(),
# Create the reactable with specific column alignments
columns = utils::modifyList(
format_num_reactable_cols(
stat_n_comp_table,
stat_n_geog_table(),
get_indicator_dps(filtered_bds()),
num_exclude = "LA Number"
),
Expand Down Expand Up @@ -452,7 +502,6 @@ StatN_StatsTableUI <- function(id) {
ns <- NS(id)

div(
style = "overflow-y: visible;",
bslib::card(
# bslib::card_header(""),
bslib::card_body(
Expand Down

0 comments on commit 36d05ce

Please sign in to comment.