Dropdown - marimo (original) (raw)
`` marimo.ui.dropdown ¶
[](#%5F%5Fcodelineno-0-1)dropdown( [](#%5F%5Fcodelineno-0-2) options: Sequence[Any] | dict[str, Any], [](#%5F%5Fcodelineno-0-3) value: Any | None = None, [](#%5F%5Fcodelineno-0-4) allow_select_none: bool | None = None, [](#%5F%5Fcodelineno-0-5) searchable: bool = False, [](#%5F%5Fcodelineno-0-6) *, [](#%5F%5Fcodelineno-0-7) label: str = "", [](#%5F%5Fcodelineno-0-8) on_change: Callable[[Any], None] | None = None, [](#%5F%5Fcodelineno-0-9) full_width: bool = False [](#%5F%5Fcodelineno-0-10))
Bases: UIElement[list[str], Any]
A dropdown selector.
Examples:
[](#%5F%5Fcodelineno-0-1)dropdown = mo.ui.dropdown( [](#%5F%5Fcodelineno-0-2) options=["a", "b", "c"], value="a", label="choose one" [](#%5F%5Fcodelineno-0-3)) [](#%5F%5Fcodelineno-0-4) [](#%5F%5Fcodelineno-0-5)# With search functionality [](#%5F%5Fcodelineno-0-6)dropdown = mo.ui.dropdown( [](#%5F%5Fcodelineno-0-7) options=["a", "b", "c"], [](#%5F%5Fcodelineno-0-8) value="a", [](#%5F%5Fcodelineno-0-9) label="choose one", [](#%5F%5Fcodelineno-0-10) searchable=True, [](#%5F%5Fcodelineno-0-11))
[](#%5F%5Fcodelineno-1-1)dropdown = mo.ui.dropdown( [](#%5F%5Fcodelineno-1-2) options={"one": 1, "two": 2, "three": 3}, [](#%5F%5Fcodelineno-1-3) value="one", [](#%5F%5Fcodelineno-1-4) label="pick a number", [](#%5F%5Fcodelineno-1-5))
Or from a dataframe series:
[](#%5F%5Fcodelineno-2-1)dropdown = mo.ui.dropdown.from_series(df["column_name"])
| ATTRIBUTE | DESCRIPTION |
|---|---|
| value | The selected value, or None if no selection. TYPE: Any |
| options | A dict mapping option name to option value. TYPE: dict |
| selected_key | The selected option's key, or None if no selection. TYPE: str |
| PARAMETER | DESCRIPTION |
|---|---|
| options | Sequence of options, or dict mapping option name to option value. If the options are not strings, they will be converted to strings when displayed in the dropdown. TYPE: Sequence[Any] | dict[str, Any] |
| value | Default option name. Defaults to None. TYPE: str DEFAULT: None |
| allow_select_none | Whether to include special option ("--") for a None value; when None, defaults to True when value is None. Defaults to None. TYPE: bool DEFAULT: None |
| searchable | Whether to enable search functionality. Defaults to False. If the number of options is greater than 1000, this will be set to True, automatically. TYPE: bool DEFAULT: False |
| label | Markdown label for the element. Defaults to "". TYPE: str DEFAULT: '' |
| on_change | Optional callback to run when this element's value changes. Defaults to None. TYPE: Callable[[Any], None] DEFAULT: None |
| full_width | Whether the input should take up the full width of its container. Defaults to False. TYPE: bool DEFAULT: False |
`` options instance-attribute ¶
`` selected_key property ¶
The selected option's key, or None if no selection.
`` text property ¶
A string of HTML representing this element.
`` value property writable ¶
The element's current value.
`` batch ¶
[](#%5F%5Fcodelineno-0-1)batch(**elements: UIElement[JSONType, object]) -> [batch](../batch/#marimo.ui.batch " marimo.ui.batch (marimo._plugins.ui._impl.batch.batch)")
Convert an HTML object with templated text into a UI element.
This method lets you create custom UI elements that are represented by arbitrary HTML.
Example
[](#%5F%5Fcodelineno-0-1)user_info = mo.md( [](#%5F%5Fcodelineno-0-2) ''' [](#%5F%5Fcodelineno-0-3) - What's your name?: {name} [](#%5F%5Fcodelineno-0-4) - When were you born?: {birthday} [](#%5F%5Fcodelineno-0-5) ''' [](#%5F%5Fcodelineno-0-6)).batch(name=mo.ui.text(), birthday=mo.ui.date())
In this example, user_info is a UI Element whose output is markdown and whose value is a dict with keys 'name' and 'birthday' (and values equal to the values of their corresponding elements).
| PARAMETER | DESCRIPTION |
|---|---|
| elements | the UI elements to interpolate into the HTML template. TYPE: UIElement[JSONType, object] DEFAULT: {} |
`` callout ¶
`callout( kind: Literal[ "neutral", "danger", "warn", "success", "info" ] = "neutral" ) -> [Html](../../html/#marimo.Html " marimo.Html
dataclass(marimo._output.hypertext.Html)") `
Create a callout containing this HTML element.
A callout wraps your HTML element in a raised box, emphasizing its importance. You can style the callout for different situations with thekind argument.
Examples:
[](#%5F%5Fcodelineno-0-1)mo.md("Hooray, you did it!").callout(kind="success")
[](#%5F%5Fcodelineno-1-1)mo.md("It's dangerous to go alone!").callout(kind="warn")
`` center ¶
Center an item.
Example
[](#%5F%5Fcodelineno-0-1)mo.md("# Hello, world").center()
| RETURNS | DESCRIPTION |
|---|---|
| Html | An Html object. |
`` form ¶
[](#%5F%5Fcodelineno-0-1)form( [](#%5F%5Fcodelineno-0-2) label: str = "", [](#%5F%5Fcodelineno-0-3) *, [](#%5F%5Fcodelineno-0-4) bordered: bool = True, [](#%5F%5Fcodelineno-0-5) loading: bool = False, [](#%5F%5Fcodelineno-0-6) submit_button_label: str = "Submit", [](#%5F%5Fcodelineno-0-7) submit_button_tooltip: str | None = None, [](#%5F%5Fcodelineno-0-8) submit_button_disabled: bool = False, [](#%5F%5Fcodelineno-0-9) clear_on_submit: bool = False, [](#%5F%5Fcodelineno-0-10) show_clear_button: bool = False, [](#%5F%5Fcodelineno-0-11) clear_button_label: str = "Clear", [](#%5F%5Fcodelineno-0-12) clear_button_tooltip: str | None = None, [](#%5F%5Fcodelineno-0-13) validate: Callable[[Optional[JSONType]], str | None] [](#%5F%5Fcodelineno-0-14) | None = None, [](#%5F%5Fcodelineno-0-15) on_change: Callable[[Optional[T]], None] | None = None [](#%5F%5Fcodelineno-0-16)) -> [form](../form/#marimo.ui.form " marimo.ui.form (marimo._plugins.ui._impl.input.form)")[S, T]
Create a submittable form out of this UIElement.
Creates a form that gates submission of a UIElement's value until a submit button is clicked. The form's value is the value of the underlying element from the last submission.
Examples:
Convert any UIElement into a form:
[](#%5F%5Fcodelineno-0-1)prompt = mo.ui.text_area().form()
Combine with HTML.batch to create a form made out of multiple UIElements:
[](#%5F%5Fcodelineno-1-1)form = ( [](#%5F%5Fcodelineno-1-2) mo.ui.md( [](#%5F%5Fcodelineno-1-3) ''' [](#%5F%5Fcodelineno-1-4) **Enter your prompt.** [](#%5F%5Fcodelineno-1-5) [](#%5F%5Fcodelineno-1-6) {prompt} [](#%5F%5Fcodelineno-1-7) [](#%5F%5Fcodelineno-1-8) **Choose a random seed.** [](#%5F%5Fcodelineno-1-9) [](#%5F%5Fcodelineno-1-10) {seed} [](#%5F%5Fcodelineno-1-11) ''' [](#%5F%5Fcodelineno-1-12) ) [](#%5F%5Fcodelineno-1-13) .batch( [](#%5F%5Fcodelineno-1-14) prompt=mo.ui.text_area(), [](#%5F%5Fcodelineno-1-15) seed=mo.ui.number(), [](#%5F%5Fcodelineno-1-16) ) [](#%5F%5Fcodelineno-1-17) .form() [](#%5F%5Fcodelineno-1-18))
| PARAMETER | DESCRIPTION | |
|---|---|---|
| label | A text label for the form. TYPE: str DEFAULT: '' | |
| bordered | Whether the form should have a border. TYPE: bool DEFAULT: True | |
| loading | Whether the form should be in a loading state. TYPE: bool DEFAULT: False | |
| submit_button_label | The label of the submit button. TYPE: str DEFAULT: 'Submit' | |
| submit_button_tooltip | The tooltip of the submit button. TYPE: str | None DEFAULT: None | |
| submit_button_disabled | Whether the submit button should be disabled. TYPE: bool DEFAULT: False | |
| clear_on_submit | Whether the form should clear its contents after submitting. TYPE: bool DEFAULT: False | |
| show_clear_button | Whether the form should show a clear button. TYPE: bool DEFAULT: False | |
| clear_button_label | The label of the clear button. TYPE: str DEFAULT: 'Clear' | |
| clear_button_tooltip | The tooltip of the clear button. TYPE: str | None DEFAULT: None | |
| validate | A function that takes the form's value and returns an error message if invalid, or None if valid. TYPE: Callable[[Optional[JSONType]], str | None] | None DEFAULT: None |
| on_change | Optional callback to run when this element's value changes. Defaults to None. TYPE: Callable[[Optional[T]], None] | None DEFAULT: None |
`` from_args classmethod ¶
[](#%5F%5Fcodelineno-0-1)from_args( [](#%5F%5Fcodelineno-0-2) data: dict[str, int], [](#%5F%5Fcodelineno-0-3) args: InitializationArgs[S, T], [](#%5F%5Fcodelineno-0-4) memo: dict[int, Any] | None = None, [](#%5F%5Fcodelineno-0-5) basis: UIElement[S, T] | None = None, [](#%5F%5Fcodelineno-0-6)) -> UIElement[S, T]
`` from_series staticmethod ¶
[](#%5F%5Fcodelineno-0-1)from_series( [](#%5F%5Fcodelineno-0-2) series: DataFrameSeries, **kwargs: Any [](#%5F%5Fcodelineno-0-3)) -> [dropdown](#marimo.ui.dropdown " marimo.ui.dropdown (marimo._plugins.ui._impl.input.dropdown)")
Create a dropdown from a dataframe series.
`` left ¶
Left-justify.
Example
[](#%5F%5Fcodelineno-0-1)mo.md("# Hello, world").left()
| RETURNS | DESCRIPTION |
|---|---|
| Html | An Html object. |
`` right ¶
Right-justify.
Example
[](#%5F%5Fcodelineno-0-1)mo.md("# Hello, world").right()
| RETURNS | DESCRIPTION |
|---|---|
| Html | An Html object. |
`` style ¶
`style( style: dict[str, Any] | None = None, **kwargs: Any ) -> [Html](../../html/#marimo.Html " marimo.Html
dataclass(marimo._output.hypertext.Html)") `
Wrap an object in a styled container.
Example
[](#%5F%5Fcodelineno-0-1)mo.md("...").style({"max-height": "300px", "overflow": "auto"}) [](#%5F%5Fcodelineno-0-2)mo.md("...").style(max_height="300px", overflow="auto")
| PARAMETER | DESCRIPTION |
|---|---|
| style | an optional dict of CSS styles, keyed by property name TYPE: dict[str, Any] | None DEFAULT: None |
| **kwargs | CSS styles as keyword arguments TYPE: Any DEFAULT: {} |