Skip to contents

[Stable]

Usage

validate_has_elements(x, msg)

Arguments

x

vector

msg

message to display

Details

This function is a wrapper for shiny::validate.

Examples

library(scda)
ADSL <- synthetic_cdisc_data("latest")$adsl

ui <- fluidPage(
  selectInput("ref_arm", "Select reference treatment",
    choices = c("ARM A", "ARM B", "ARM X"), selected = "ARM A"
  ),
  selectInput("comp_arm", "Select comparison treatment",
    choices = c("ARM C", "ARM Y", "ARM Z"), selected = "ARM C"
  ),
  verbatimTextOutput("arm_summary")
)

server <- function(input, output) {
  output$arm_summary <- renderText({
    ref_arm <- ADSL$ARMCD[input$ref_arm == ADSL$ARMCD]
    comp_arm <- ADSL$ARMCD[input$comp_arm == ADSL$ARMCD]

    validate_has_elements(ref_arm, "Need reference treatment.")
    validate_has_elements(comp_arm, "Need comparison treatment.")

    paste0(
      "Number of patients in: reference treatment=",
      length(ref_arm), " comparions treatment=", length(comp_arm)
    )
  })
}
if (FALSE) {
shinyApp(ui, server)
}