0

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!

MrFlick
  • 195,160
  • 17
  • 277
  • 295
Sean
  • 57
  • 6
  • You can mark a question as solved by accepted a proposed answer. If none of the provided answers work for you, feel free to post your own solution. Do not edit your question to include a solution. The community will decide which answer it likes best by voting. – MrFlick Dec 13 '22 at 02:58
  • No worries - where can I post my own solutions? (apologies, am still new to SO) – Sean Dec 13 '22 at 03:07
  • You can post an answer below your question just like any other post. – MrFlick Dec 13 '22 at 03:08

2 Answers2

0

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

Pedro
  • 196
  • 3
  • 16
  • Hi, thank you for your time in replying. Unfortunately this isn't what I am looking for. These are radiobuttons, and do what I want, but the aesthetic is different. They need to look exactly the same as checkboxGroupButtons - group of horizontal square boxes that only allow for one selection. – Sean Dec 13 '22 at 01:39
  • Try to use the "selectize = TRUE" argument inside checkboxGroupButtons, for instance, immediately bellow your "choices". It should do what you are looking for. :) – Pedro Dec 13 '22 at 01:44
  • doesn't work, met with error: ``` Error in checkboxGroupButtons(inputId = "somevalue1", label = "Make a choice: ", : unused argument (selectize = TRUE) ``` – Sean Dec 13 '22 at 01:47
  • That's much probably because your shinyWidgets package version is inferior to v0.5.0. Please try to update and it will work. – Pedro Dec 13 '22 at 01:51
  • I have version 0.7.5 - will try rolling back to v0.5.0 – Sean Dec 13 '22 at 01:58
  • Same error - it appears that checkboxGroupButtons simply does not support the selectize argument – Sean Dec 13 '22 at 02:06
  • I wish I could help you further but I really can't understand why it does not work, it should. There must be something else messing with that. :( – Pedro Dec 13 '22 at 02:33
  • It's because the selectize argument isn't supported by the checkboxGroupButtons function - it's not coded for it. – Sean Dec 13 '22 at 02:46
0

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

Sean
  • 57
  • 6