Skip to content

Commit

Permalink
Rejig create own (#43)
Browse files Browse the repository at this point in the history
* Feat: Added first iteration of clear all selections button

* Feat: Adding handling for year_range to be cleared

* Chore: More consistent handling of sharing the clear_all to remove the chosen years

* Feat: Moved add selection sbutton down next to staging table and styled as a start gov button

* Feat: Adding new Create Own layout to main ui and server scripts

* Feat: Adding gov spinner to metadata
  • Loading branch information
JT-39 authored Nov 22, 2024
1 parent 726f803 commit 684e380
Show file tree
Hide file tree
Showing 6 changed files with 692 additions and 645 deletions.
6 changes: 4 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 @@ -36,9 +36,10 @@ ui <- bslib::page_fillable(
Create_MainInputsUI("create_inputs")["LA grouping"],
Create_MainInputsUI("create_inputs")["Other grouping"],
YearRangeUI("year_range"),
Create_MainInputsUI("create_inputs")["Add selection"]
Create_MainInputsUI("create_inputs")["Clear all current selections"]
)
),
# Staging table and Add selections button
StagingTableUI("staging_table"),
QueryTableUI("query_table"),
CreateOwnTableUI("create_own_table"),
Expand Down Expand Up @@ -66,7 +67,8 @@ server <- function(input, output, session) {
year_input <- YearRangeServer(
"year_range",
bds_metrics,
create_inputs$indicator
create_inputs$indicator,
create_inputs$clear_selections
)

# Geog Groupings
Expand Down
36 changes: 34 additions & 2 deletions R/lait_modules/mod_create_own_inputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,23 @@ Create_MainInputsUI <- function(id) {
shiny::checkboxInput(ns("inc_regions"), "Include All Regions", FALSE),
shiny::checkboxInput(ns("inc_england"), "Include England", FALSE)
),
# Clear all current selections
"Clear all current selections" = div(
style = "height: 100%; display: flex; justify-content: center; align-items: flex-end;",
shinyGovstyle::button_Input(
inputId = ns("clear_all"),
label = "Clear all current selections",
type = "warning"
)
),
# Add selection (query) button
"Add selection" = div(
style = "height: 100%; display: flex; justify-content: center; align-items: flex-end;",
shiny::actionButton(ns("add_query"), "Add selections", class = "gov-uk-button")
shinyGovstyle::button_Input(
inputId = ns("add_query"),
label = "Add selections",
type = "start"
)
)
)
}
Expand Down Expand Up @@ -166,6 +179,19 @@ Create_MainInputsServer <- function(id, bds_metrics) {
ignoreNULL = FALSE
)

# Clear all current selections
observeEvent(input$clear_all, {
# Reset inputs to their initial state
updateSelectizeInput(session, "geog_input", selected = NA)
updateSelectizeInput(session, "indicator", selected = NA)
updateRadioButtons(session, "la_group", selected = "no_groups")
updateCheckboxInput(session, "inc_regions", value = FALSE)
updateCheckboxInput(session, "inc_england", value = FALSE)

# Emit a reset signal for year_range
session$sendCustomMessage("clear_year_range", TRUE)
})

# Return create your own main inputs
create_inputs <- list(
geog = reactive(input$geog_input),
Expand All @@ -175,6 +201,7 @@ Create_MainInputsServer <- function(id, bds_metrics) {
la_group = reactive(input$la_group),
inc_regions = reactive(input$inc_regions),
inc_england = reactive(input$inc_england),
clear_selections = reactive(input$clear_all),
add_query = reactive(input$add_query)
)

Expand Down Expand Up @@ -223,7 +250,7 @@ YearRangeUI <- function(id) {
#' @return A list containing reactive values for selected year range
#' and available year choices.
#'
YearRangeServer <- function(id, bds_metrics, indicator_input) {
YearRangeServer <- function(id, bds_metrics, indicator_input, clear_selections) {
moduleServer(id, function(input, output, session) {
# Compute years choices available based on selected indicator
years_choices <- reactive({
Expand Down Expand Up @@ -272,6 +299,11 @@ YearRangeServer <- function(id, bds_metrics, indicator_input) {
}
})

# Reset year range when clear all current selections button clicked
observeEvent(clear_selections(), {
shinyWidgets::updatePickerInput(session, "year_range", selected = NULL)
})

# Collect selected year range and available year choices
# (choices are used in query table to set year range info)
year_input <- list(
Expand Down
10 changes: 9 additions & 1 deletion R/lait_modules/mod_create_own_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,14 @@ StagingTableUI <- function(id) {
div(
class = "well",
style = "overflow-y: visible;",
h3("Staging Table (View of current selections)"),
bslib::layout_column_wrap(
h3("Staging Table (View of current selections)"),
# Include empty divs so matches inputs above and add selections aligns
div(),
div(),
# Add selections button
Create_MainInputsUI("create_inputs")["Add selection"]
),
bslib::card(
with_gov_spinner(
reactable::reactableOutput(ns("staging_table")),
Expand All @@ -207,6 +214,7 @@ StagingTableUI <- function(id) {
)
}


# Staging table Server ---------------------------------------------------------
# Output a formatted reactable table of the staging data
# Few error message table outputs for incorrect/ missing selections
Expand Down
Loading

0 comments on commit 684e380

Please sign in to comment.