Batch#

class marimo.ui.batch(html: Html, elements: dict[str, marimo._plugins.ui._core.ui_element.UIElement[Any, Any]], on_change: Callable[[Dict[str, object]], None] | None = None)#

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

A batch is a UI element that wraps other UI elements, and is represented by custom HTML or markdown. You can create a batch by calling the batch() method on Html objects.

Example.

user_info = mo.md(
    '''
    - What's your name?: {name}
    - When were you born?: {birthday}
    '''
).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).

You can also instantiate this class directly:

markdown = mo.md(
    '''
    - What's your name?: {name}
    - When were you born?: {birthday}
    '''
)
batch = mo.ui.batch(
    markdown, {"name": mo.ui.text(), "birthday": mo.ui.date()}
)

Attributes.

  • value: a dict of the batched elements’ values

  • elements: a dict of the batched elements (clones of the originals)

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

Initialization Args.

  • html: a templated Html object

  • elements: the UI elements to interpolate into the HTML template

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

Public methods

Inherited from UIElement

form([label])

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.

Public Data Attributes:

Inherited from _batch_base

elements

Inherited from UIElement

value

The element’s current value.

Inherited from Html

text

A string of HTML representing this element.