shiny.ui.input_radio_buttons#

shiny.ui.input_radio_buttons(id, label, choices, *, selected=None, inline=False, width=None)#

Create a set of radio buttons used to select an item from a list.

Parameters
  • id (str) – An input id.

  • label (Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[ForwardRef]]]]) – An input label.

  • choices (Union[List[str], Mapping[str, Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[Union[Tagifiable, Tag, MetadataNode, str, TagList, float, None, Dict[str, Union[str, float, bool, None]], Sequence[ForwardRef]]]]]]) – Either a list of choices or a dictionary mapping choice values to labels. Note that if a dictionary is provided, the keys are used as the (input) values so that the dictionary values can hold HTML labels.

  • selected (Optional[str]) – The values that should be initially selected, if any.

  • inline (bool) – If True, the result is displayed inline

  • width (Optional[str]) – The CSS width, e.g. ‘400px’, or ‘100%’

Return type

A UI element

Notes

Server value

A string with the selected value.

Example

#| standalone: true
#| components: [editor, viewer]
#| layout: vertical
#| viewerHeight: 400
from shiny import *
from htmltools import HTML

app_ui = ui.page_fluid(
    ui.input_radio_buttons(
        "rb",
        "Choose one:",
        {
            "html": HTML("Red Text"),
            "text": "Normal text",
        },
    ),
    ui.output_ui("val"),
)

def server(input: Inputs, output: Outputs, session: Session):
    @output
    @render.ui
    def val():
        return "You chose " + input.rb()


app = App(app_ui, server)