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 abatch
by calling thebatch()
method onHtml
objects.Get the value of the wrapped UI elements using the
value
attribute of the batch.Example.
In the below 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).user_info = mo.md( ''' - What's your name?: {name} - When were you born?: {birthday} ''' ).batch(name=mo.ui.text(), birthday=mo.ui.date())
To get the value of
name
andbirthday
, use:user_info.value
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
: adict
of the batched elements’ valueselements
: adict
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
objectelements: 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
_batch_base
get
(key[, default])items
()values
()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:
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.