insightsengineering / teal.modules.general

General Purpose Teal Modules
https://insightsengineering.github.io/teal.modules.general/
Other
9 stars 13 forks source link

Create facet settings UI module #62

Open cicdguy opened 3 years ago

cicdguy commented 3 years ago

After #804 three tmg modules all use facetting (and more will probably use it in the future). This task is to create a shiny module to handle facetting and to update the modules to use it.

Note it may make sense for this to live in teal.devel?

NEST/teal.devel/issues/538 ``` #' TODO facet_settings_ui <- function(id, row_facet, col_facet, is_single_dataset_value = FALSE, free_x_scales = FALSE, free_y_scales = FALSE, facet_on = TRUE) { stopifnot(is_character_single(id)) #Add more stopif nots ns <- NS(id) if (!is.null(row_facet) || !is.null(col_facet)) { div( class = "data-extract-box", tags$label("Facetting"), switchInput(inputId = ns("facetting"), value = facet_on, size = "mini"), conditionalPanel( condition = paste0("input['", ns("facetting"), "']"), div( if (!is.null(row_facet)) { data_extract_input( id = ns("row_facet"), label = "Row facetting variable", data_extract_spec = row_facet, is_single_dataset = is_single_dataset_value ) }, if (!is.null(col_facet)) { data_extract_input( id = ns("col_facet"), label = "Column facetting variable", data_extract_spec = col_facet, is_single_dataset = is_single_dataset_value ) }, checkboxInput(ns("free_x_scales"), "free x scales", value = free_x_scales), checkboxInput(ns("free_y_scales"), "free y scales", value = free_y_scales) ) ) ) } } #' TODO facet_settings_srv <- function(input, output, session) { return( list( facet_on = reactive(input$facetting), col_facet = reactive(input$`col_facet-dataset_ADSL_singleextract-select`), #TO CHANGE row_facet = reactive(input$`row_facet-dataset_ADSL_singleextract-select`), #TO CHANGE free_x_scales = reactive(input$free_x_scales), free_y_scales = reactive(input$free_y_scales) ) ) } ``` Provenance: ``` Creator: nikolas-burkoff ```
cicdguy commented 3 years ago

@nikolas-burkoff if we create legit module it can go to the teal.devel, otherwise we can consider it as utils for tmg.

In facet_settings_srv you can call data_extract_module instead of searching for element id - but I'm not sure how to combine this with data_merge_module which needs also facet vars to be selected in merge.

callModule(
        data_extract_module,
        id = "facet_col",
        datasets = datasets,
        data_extract_spec = facet_col_spec
      )

Provenance:

Creator: gogonzo
nikolas-burkoff commented 2 years ago

We should make sure whatever is done works with shinyvalidate