diff --git a/02_dev/stat_n_level_page/stat_n_dev_app_mod.R b/02_dev/stat_n_level_page/stat_n_dev_app_mod.R index 390d5d8..1b8bd1a 100644 --- a/02_dev/stat_n_level_page/stat_n_dev_app_mod.R +++ b/02_dev/stat_n_level_page/stat_n_dev_app_mod.R @@ -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;", @@ -74,7 +59,7 @@ 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 @@ -82,7 +67,7 @@ server_mod <- function(input, output, session) { # LA geographic comparison table -------------------------------------------- StatN_GeogCompTableServer( - "stat_n_comp_table", + "stat_n_tables", app_inputs, bds_metrics, stat_n_la @@ -90,7 +75,7 @@ server_mod <- function(input, output, session) { # Statistics Table ---------------------------------------------------------- StatN_StatsTableServer( - "stat_n_stats_table", + "stat_n_stats_mod", app_inputs, bds_metrics, stat_n_la, diff --git a/R/lait_modules/mod_stat_n_table.R b/R/lait_modules/mod_stat_n_table.R index 2b32b60..f534575 100644 --- a/R/lait_modules/mod_stat_n_table.R +++ b/R/lait_modules/mod_stat_n_table.R @@ -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") + ) + ) + ) } @@ -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 ) @@ -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" ), @@ -452,7 +502,6 @@ StatN_StatsTableUI <- function(id) { ns <- NS(id) div( - style = "overflow-y: visible;", bslib::card( # bslib::card_header(""), bslib::card_body(