Array#

class marimo.ui.array(elements: Sequence[UIElement[Any, Any]], *, label: str = '', on_change: Callable[[Sequence[object]], None] | None = None)#

An array of UI elements.

Use an array to

  • create a set of UI elements at runtime

  • group together logically related UI elements

  • keep the number of global variables in your program small

The UI elements in the array are clones of the original elements: interacting with the array will not update the original elements, and vice versa.

Examples.

A heterogeneous collection of UI elements:

array = mo.ui.array([mo.ui.slider(1, 10), mo.ui.text(), mo.ui.date()])
# array.value returns a list with the values of the elements
array.value

Some number of UI elements, determined at runtime:

mo.ui.array([mo.ui.slider(1, 10) for _ in range random.randint(4, 8)])

Attributes.

  • value: a list containing the values of the array’s entries

  • elements: a list of the wrapped elements (clones of the originals)

Initialization Args.

  • elements: the UI elements to include

  • label: a descriptive name for the array

  • 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:

elements

Inherited from UIElement

value

The element’s current value.

Inherited from Html

text

A string of HTML representing this element.