Table¶
- class marimo.ui.table(data: ListOrTuple[str | int | float | bool | MIME | None] | ListOrTuple[Dict[str, JSONType]] | Dict[str, ListOrTuple[JSONType]] | 'IntoDataFrame', pagination: bool | None = None, selection: Literal['single', 'multi'] | None = 'multi', page_size: int = 10, show_column_summaries: bool | None = None, format_mapping: Dict[str, str | Callable[..., Any]] | None = None, freeze_columns_left: Sequence[str] | None = None, freeze_columns_right: Sequence[str] | None = None, text_justify_columns: Dict[str, Literal['left', 'center', 'right']] | None = None, wrapped_columns: List[str] | None = None, show_download: bool = True, max_columns: int | None = 50, *, label: str = '', on_change: Callable[[List[JSONType] | Dict[str, ListOrTuple[JSONType]] | 'IntoDataFrame'], None] | None = None, _internal_column_charts_row_limit: int | None = None, _internal_summary_row_limit: int | None = None, _internal_total_rows: int | Literal['too_many'] | 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; or
an Ibis dataframe; or
a PyArrow table.
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", )
Create a table with format mapping:
# format_mapping is a dict keyed by column names, # with values as formatting functions or strings def format_name(name): return name.upper() table = mo.ui.table( data=[ {"first_name": "Michael", "last_name": "Scott", "age": 45}, {"first_name": "Dwight", "last_name": "Schrute", "age": 40}, ], format_mapping={ "first_name": format_name, # Use callable to format first names "age": "{:.1f}".format, # Use string format for age }, label="Format Mapping", )
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
: Values can be primitives (str
,int
,float
,bool
, orNone
) or marimo elements: e.g.mo.ui.button(...)
,mo.md(...)
,mo.as_html(...)
, etc. Data can be passed in many ways:as dataframes: a pandas dataframe, a polars dataframe
as rows: a list of dicts, where each dict represents a row in the table
as columns: a dict keyed by column names, where the value of each entry is a list representing a column
as a single column: a list of values
pagination
: whether to paginate; ifFalse
, all rows will be shown defaults toTrue
when above 10 rows,False
otherwiseselection
: ‘single’ or ‘multi’ to enable row selection, orNone
to disablepage_size
: the number of rows to show per page. defaults to 10show_column_summaries
: whether to show column summaries defaults toTrue
when the table has less than 40 columns,False
otherwiseshow_download
: whether to show the download button defaults toTrue
for dataframes,False
otherwiseformat_mapping
: a mapping from column names to formatting strings or functionsfreeze_columns_left
: list of column names to freeze on the leftfreeze_columns_right
: list of column names to freeze on the righttext_justify_columns
: dictionary of column names to text justification options:left
,center
,right
wrapped_columns
: list of column names to wraplabel
: markdown label for the elementon_change
: optional callback to run when this element’s value changesmax_columns
: maximum number of columns to display, defaults to 50. Set to None to show all columns.
Public methods
download_as
(args)get_column_summaries
(args)search
(args)Inherited from
UIElement
form
([label, bordered, loading, ...])Create a submittable form out of this
UIElement
.send_message
(message, buffers)Send a message to the element rendered on the frontend from the backend.
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.