Radio

class marimo.ui.radio(options: Sequence[str] | dict[str, Any], value: str | None = None, inline: bool = False, *, label: str = '', on_change: Callable[[Any], None] | None = None)

A radio group.

Example.

radiogroup = mo.ui.radio(
    options=["a", "b", "c"], value="a", label="choose one"
)
radiogroup = mo.ui.radio(
    options={"one": 1, "two": 2, "three": 3},
    value="one",
    label="pick a number",
)

Or from a dataframe series:

radiogroup = mo.ui.radio.from_series(df["column_name"])

Attributes.

  • value: the value of the selected radio option

  • options: a dict mapping option name to option value

Initialization Args.

  • options: sequence of text options, or dict mapping option name to option value

  • value: default option name, if None, starts with nothing checked

  • label: optional text label for the element

  • on_change: optional callback to run when this element’s value changes

Public methods

from_series(series, **kwargs)

Create a radio group from a dataframe series.

Inherited from UIElement

form([label, bordered, loading, ...])

Create a submittable form out of this UIElement.

send_message(message, buffers)

Send a message to the element rendered on the frontend from the backend.

Inherited from Html

batch(**elements)

Convert an HTML object with templated text into a UI element.

center()

Center an item.

right()

Right-justify.

left()

Left-justify.

callout([kind])

Create a callout containing this HTML element.

style([style])

Wrap an object in a styled container.

Public Data Attributes:

Inherited from UIElement

value

The element’s current value.

Inherited from Html

text

A string of HTML representing this element.


static from_series(series: DataFrameSeries, **kwargs: Any) radio

Create a radio group from a dataframe series.