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
predicate
isTrue
When
predicate
isTrue
, this function raises aMarimoStopError
. If uncaught, this exception stops execution of the current cell and makesoutput
its 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
predicate
isTrue
, raises aMarimoStopError
.
- class marimo.MarimoStopError(output: object | None)¶
Raised by
marimo.stop
to stop execution of a cell and descendants.Inherits from
BaseException
to prevent accidental capture withexcept Exception
(similar toKeyboardInterrupt
)
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”).
Note: The refresh interval may not be exact, as it depends on the time it takes to render the content and the time it takes to send the content to the client. Also, due to the buffering of UI element changes, if the downstream cells take a long time to render, the refresh interval may be longer than expected.
Example.
refresh_button = mo.ui.refresh( options=["1m", "5m 30s", "10m"], default_interval="10m", ) refresh_button
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
UIElement
form
([label, bordered, loading, ...])Create a submittable form out of this
UIElement
.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:
name
Inherited from
UIElement
value
The element’s current value.
Inherited from
Html
text
A string of HTML representing this element.