Table#
- class marimo.ui.table(data: ListOrTuple[str | int | float | bool | MIME | None] | ListOrTuple[dict[str, JSONType]] | 'pd.DataFrame' | 'pl.DataFrame', pagination: bool | None = None, selection: Literal['single', 'multi'] | None = 'multi', page_size: int = 10, *, label: str = '', on_change: Callable[[List[JSONType] | 'pd.DataFrame' | 'pl.DataFrame'], None] | None = None)#
A table component with selectable rows. Get the selected rows with
table.value
.The table data can be supplied a:
a list of dicts, with one dict for each row, keyed by column names;
a list of values, representing a table with a single column;
a Pandas dataframe; or
a Polars dataframe.
Examples.
Create a table from a list of dicts, one for each row.
table = mo.ui.table( data=[ {'first_name': 'Michael', 'last_name': 'Scott'}, {'first_name': 'Dwight', 'last_name': 'Schrute'} ], label='Users' )
Create a table from a single column of data:
table = mo.ui.table( data=[ {‘first_name’: ‘Michael’, ‘last_name’: ‘Scott’}, {‘first_name’: ‘Dwight’, ‘last_name’: ‘Schrute’} ], label=‘Users’ )
Create a table from a dataframe:
# df is a Pandas or Polars dataframe table = mo.ui.table( data=df, # use pagination when your table has many rows pagination=True, label='Dataframe' )
In each case, access the table data with
table.value
.Attributes.
value
: the selected rows, in the same format as the original data, orNone
if no selectiondata
: the original table data
Initialization Args.
data
: A pandas dataframe, a polars dataframe, a list of values representing a column, or a list of dicts where each dict represents a row in the table (mapping column names to values). Values can be primitives (str
,int
,float
,bool
, orNone
) or marimo elements: e.g.mo.ui.button(...)
,mo.md(...)
,mo.as_html(...)
, etc.pagination
: whether to paginate; ifFalse
, all rows will be shown defaults toTrue
when above 10 rows,False
otherwisepage_size
: the number of rows to show per page. defaults to 10selection
: ‘single’ or ‘multi’ to enable row selection, orNone
to disablelabel
: text label for the elementon_change
: optional callback to run when this element’s value changes
Public methods
download_as
(args)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:
data
Inherited from
UIElement
value
The element’s current value.
Inherited from
Html
text
A string of HTML representing this element.