R/module_render_group_summary_checkbox.R

Defines functions module_server_checkbox module_ui_checkbox

Documented in module_server_checkbox module_ui_checkbox

# UI ----------------------------------------------------------------------



#' UI Module: data summary
#'
#' @param id shiny standard
#' @param cond_id character,
#'
#'
module_ui_checkbox <- function(id, cond_id) {
  ns <- shiny::NS(id)



  if (!is.character(cond_id)) {
    stop("supply string matching an input/output namespace.")
  }

  space <- "output."

  shiny::tagList(
    # shiny::conditionalPanel(condition = paste0(space, cond_id, " !== null"),
    shiny::conditionalPanel(
      condition = paste0("input['", cond_id, "'] != ''"),
      shiny::htmlOutput(ns("checkbox"))
    )
  )
}



# Server ------------------------------------------------------------------





#' Server Module: checkbox rendering
#'
#' @param input,output,session standard \code{shiny} boilerplate
#' @param text Character, appears next to checkbox (or coerced)
module_server_checkbox <- function(input, output, session, text) {
  output$checkbox <- shiny::renderUI({
    ns <- session$ns

    shiny::checkboxInput(ns("checkbox"),
      label = text,
      value = FALSE,
      width = NULL
    )
  })

  check_val <- shiny::reactiveVal()

  shiny::observe({
    if (!is.null(input$checkbox)) {
      check_val(input$checkbox)
    } else {
      check_val(FALSE)
    }
  })


  return(check_val)
}

Try the datacleanr package in your browser

Any scripts or data that you put into this service are public.

datacleanr documentation built on June 8, 2025, 10:27 a.m.