简体   繁体   中英

checkboxGroupButton - Select one at a time

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!

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".

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM