Skip to contents

Usage

RadioGroup(...)

RadioGroup.shinyInput(inputId, ..., value = defaultValue)

updateRadioGroup.shinyInput(
  session = shiny::getDefaultReactiveDomain(),
  inputId,
  ...
)

Arguments

...

Props to pass to the component.

inputId

ID of the component.

value

Starting value.

session

Object passed as the `session` argument to Shiny server.

Value

Object with shiny.tag class suitable for use in the UI of a Shiny app.

Details

  • children node
    Default is NA The content of the component.

  • defaultValue any
    Default is NA The default value. Use when the component is not controlled.

  • name string
    Default is NA The name used to reference the value of the control. If you don't provide this prop, it falls back to a randomly generated name.

  • onChange func
    Default is NA Callback fired when a radio button is selected.Signature:function(event: React.ChangeEvent, value: string) = voidevent The event source of the callback.value The value of the selected radio button. You can pull out the new value by accessing event.target.value (string).

  • value any
    Default is NA Value of the selected radio button. The DOM API casts this to a string.

Examples

RadioGroup(
  defaultValue = "female",
  name = "gender",
  FormControlLabel(value = "female", control = Radio(), label = "Female"),
  FormControlLabel(value = "male", control = Radio(), label = "Male")
)
#> <div class="react-container" data-react-id="jpkftlcucajioogbybjh">
#>   <script class="react-data" type="application/json">{"type":"element","module":"@mui/material","name":"RadioGroup","props":{"type":"object","value":{"defaultValue":{"type":"raw","value":"female"},"name":{"type":"raw","value":"gender"},"children":{"type":"array","value":[{"type":"element","module":"@mui/material","name":"FormControlLabel","props":{"type":"object","value":{"value":{"type":"raw","value":"female"},"control":{"type":"element","module":"@mui/material","name":"Radio","props":{"type":"raw","value":[]}},"label":{"type":"raw","value":"Female"}}}},{"type":"element","module":"@mui/material","name":"FormControlLabel","props":{"type":"object","value":{"value":{"type":"raw","value":"male"},"control":{"type":"element","module":"@mui/material","name":"Radio","props":{"type":"raw","value":[]}},"label":{"type":"raw","value":"Male"}}}}]}}}}</script>
#>   <script>jsmodule['@/shiny.react'].findAndRenderReactData('jpkftlcucajioogbybjh')</script>
#> </div>
if (FALSE) { # interactive()
library(shiny)
ui <- muiMaterialPage(
  RadioGroup.shinyInput(
    inputId = "gender",
    value = "female",
    FormControlLabel(value = "female", control = Radio(), label = "Female"),
    FormControlLabel(value = "male", control = Radio(), label = "Male")
  ),
  verbatimTextOutput("out")
)
server <- function(input, output, session) output$out <- renderPrint(input$gender)
shinyApp(ui, server)
}