conditionalPanel condition contained in a list

So, I have a checkboxgroupButtons where the user can select one or more options

checkboxGroupButtons("id","select options",
                             choices = c( "A","B","C" )
                             ,selected = "A"
                            , checkIcon = list(yes = icon("ok", lib = "glyphicon"))
                             , direction = "vertical"
                 )

Then I want a conditional panel, but I want it such that the action depends if user selects "A" or (inclusive) "B". Already tried &&. Tried || but it doesn't logically accepts the inclusion. also tried input.id.values, but it triggers even if I select "A" and "C".

conditionalPanel( condition = "input.id=='A' || input.id=='B'" , helpText("something") )

How can I set a condition is : "input.id" contained in the list ("A","B") ?

Thank you

This displays the conditional panel if A or B or both are selected. Is that what you want?

conditionalPanel( condition = "(input.id[0]=='A' || input.id=='B')" , helpText("something"),
                      tableOutput("Table1"))

Thanks, it didn't worked :confused:

Here is the complete code of my app.R file. Checking box A or B or both displays the table.

library(shiny)
DF <- data.frame(A = 1:4, B = 11:14)

ui <- pageWithSidebar(
  headerPanel("My First Shiny App"),
  
  sidebarPanel( 
    checkboxGroupInput("id","select options",
                         choices = c( "A","B","C" )
                         ,selected = "A"
    ) 
  ),     
  mainPanel(
    conditionalPanel( condition = "(input.id[0]=='A' || input.id=='B')" , helpText("something"),
                      tableOutput("Table1"))
    
  )
)

server <- function(input, output, session){
    output$Table1 <-renderTable({
    DF
  })
}
 
shinyApp(ui = ui, server = server)

Umm it triggers the action even if I select "A" and "C"

library(shiny)
DF <- data.frame(A = 1:4, B = 11:14)

ui <- pageWithSidebar(
  headerPanel("My First Shiny App"),

  sidebarPanel(
    checkboxGroupInput("id", "select options",
      choices = c("A", "B", "C"),
      selected = "A"
    )
  ),
  mainPanel(
    uiOutput("possible_table")
  )
)

server <- function(input, output, session) {
  show_table_flag <- reactive({
    (("A" %in% input$id | "B" %in% input$id) & !"C" %in% input$id)
  })
  output$Table1 <- renderTable({
    DF
  })

  output$possible_table <- renderUI({
    if (show_table_flag()) {
      tableOutput("Table1")
    }
  })
}

shinyApp(ui, server)

Oops, I answered the question that I imagined, not the one you asked. Sorry!

1 Like