Control flow#
Use mo.stop to halt execution of a cell, and optionally output an object.
This function is useful for validating user input.
- marimo.stop(predicate: bool, output: object | None = None) None#
Stops execution of a cell when
predicateisFalseWhen
predicateisTrue, this function raises aMarimoStopError. If uncaught, this exception stops execution of the current cell and makesoutputits output. Any descendants of this cell that were previously scheduled to run will not be run, and their defs will be removed from program memory.Example:
mo.stop(form.value is None, mo.md("**Submit the form to continue.**"))
Raises:
When
predicateisTrue, raises aMarimoStopError.
- class marimo.MarimoStopError(output: object | None)#
Raised by
marimo.stopto stop execution of a cell and descendants.
Use mo.ui.refresh to trigger other cells to run periodically, on a configurable
interval (or on click).
- class marimo.ui.refresh(options: list[Union[int, float, str]] | None = None, default_interval: int | float | str | None = None, *, label: str = '', on_change: Callable[[int], None] | None = None)#
A refresh button that will auto-refresh its descendants for a given interval.
Each option value can either be a number (int or float) in seconds or a human-readable string (e.g. “1s”, “10s”, “1m”).
You can also combine multiple time units (e.g. “1m 30s”).
Example.
refresh_button = mo.ui.refresh_button( options=["1m", "5m 30s", "10m"], default_interval="10m", )
Attributes.
value: The time in seconds since the refresh has been activated.
Initialization Args.
options: The options for the refresh interval, as a list of human-readable strings or numbers (int or float) in seconds. If no options are provided and default_interval is provided, the options will be generated automatically. If no options are provided and default_interval is not provided, the refresh button will not be displayed with a dropdown for auto-refresh.default_interval: The default value of the refresh interval.label: optional text label for the elementon_change: optional callback to run when this element’s value changes
Public methods
Inherited from
UIElementform([label])Create a submittable form out of this
UIElement.Inherited from
Htmlbatch(**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.
Public Data Attributes:
nameInherited from
UIElementvalueThe element’s current value.
Inherited from
HtmltextA string of HTML representing this element.