Lazy#

marimo.lazy(element: Callable[[], object] | object, show_spinner: bool = False) None#

Lazy load a component until it is visible.

This be a marimo element or any HTML content. This is useful for loading expensive components only when they are needed.

This defers any frontend rendering until the content is visible.

If the content is a function, it will additionally be lazily evaluated in Python as well. This is useful for database queries or other expensive operations.

Examples.

Create a lazy-loaded tab:

tabs = mo.ui.tabs({
    "Overview": tab1,
    "Charts": mo.lazy(expensive_component)
})

Create a lazy-loaded accordion:

accordion = mo.ui.accordion({
    "Charts": mo.lazy(expensive_component)
})

Initialization Args.

  • element: content or callable that returns content to be lazily loaded

  • show_spinner: a boolean, whether to show a loading spinner while. Default is False.