I have a basic shiny app below with a checkbox group and the printed results of it. I was wondering if it is possible to somehow hide one of the 3 choices (for example "1") but the printed result should still include "1".

#ui.r
fluidPage(

  # Copy the chunk below to make a group of checkboxes
  checkboxGroupInput("checkGroup", label = h3("Checkbox group"), 
    choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3),
    selected = 1),


  hr(),
  fluidRow(column(3, verbatimTextOutput("value")))

)
#server.r
function(input, output) {

  # You can access the values of the widget (as a vector)
  # with input$checkGroup, e.g.
  output$value <- renderPrint({ input$checkGroup })

}

2 Answers

2
St├ęphane Laurent On Best Solutions

With CSS:

ui <- fluidPage(

  tags$head(
    tags$style(HTML("input[name=checkGroup][value='1'] { display: none }"))
  ),

  checkboxGroupInput("checkGroup", label = h3("Checkbox group"), 
                     choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3),
                     selected = 1),
  hr(),
  fluidRow(column(3, verbatimTextOutput("value")))

)
1
phalteman On

It isn't a checkboxGroupInput, but it mimics the idea...

library(shiny)

ui <- fluidPage(

  # Copy the chunk below to make a group of checkboxes
  checkboxGroupInput("checkGroup", label = h3("Checkbox group"), 
                     choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3),
                     selected = 1),
  hr(),
  conditionalPanel(
    "input.check1 == 'T'",
    checkboxInput("check1", "Choice 1", value = T)
  ),
  checkboxInput("check2", "Choice 2", value = F),
  checkboxInput("check3", "Choice 3", value = F),
  hr(),
  fluidRow(column(3, verbatimTextOutput("value"))),
  fluidRow(column(3, verbatimTextOutput("value2")))

)

server <- function(input, output) {

  # You can access the values of the widget (as a vector)
  # with input$checkGroup, e.g.
  output$value <- renderPrint({ input$checkGroup })
  output$value2 <- renderPrint({ c(input$check1, input$check2, input$check3)})

}

shinyApp(ui, server)