Home > Mobile >  checkboxGroupButton - Select one at a time
checkboxGroupButton - Select one at a time

Time:12-14

I'm trying to create a radiobutton in the style of the checkboxGroupButton() in R shiny.

I want to recreate this example with the same button aesthetics, but only allow the user to select one input at a time.

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  tags$h1("checkboxGroupButtons examples"),
  
  checkboxGroupButtons(
    inputId = "somevalue1",
    label = "Make a choice: ",
    choices = c("A", "B", "C")
  ),
  verbatimTextOutput("value1")
)
  
 

server <- function(input, output) {
  
  output$value1 <- renderPrint({ input$somevalue1 })

  
}

if (interactive())
  shinyApp(ui, server)

Thanks!

CodePudding user response:

To create a radiobutton with the same button aesthetics as the checkboxGroupButton() function in R shiny, you can use the radioButtons() function. This function allows you to create a group of radio buttons that the user can select from, but only allows the user to select one option at a time.

So this means it would look something like this:

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  tags$h1("Radiobutton examples"),
  
  radioButtons(
    inputId = "somevalue1",
    label = "Make a choice: ",
    choices = c("A", "B", "C")
  ),
  verbatimTextOutput("value1")
)

server <- function(input, output) {  
  output$value1 <- renderPrint({ input$somevalue1 })
}

if (interactive())
  shinyApp(ui, server)

Hope this helps! :)

Or if you really want to use the checkboxes, then use the argument "selectize = TRUE", for instance, immediately bellow your argument "choices".

CodePudding user response:

Figured it out - can simply be solved by replacing the checkboxGroupButtons() function with radioGroupButtons()

  • Related