Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: add show_column_summaries config to mo.ui.table (#1584)

Myles Scolnick9ae0945187fc
diff --git a/frontend/src/components/data-table/column-header.tsx b/frontend/src/components/data-table/column-header.tsx
index 1e9178c349..df1eb419f4 100644
--- a/frontend/src/components/data-table/column-header.tsx
+++ b/frontend/src/components/data-table/column-header.tsx
@@ -44,7 +44,7 @@ export const DataTableColumnHeader = <TData, TValue>({
<DropdownMenuTrigger asChild={true}>
<div
className={cn(
- "group flex items-center space-between w-full select-none gap-2 border hover:border-border border-transparent hover:bg-[var(--slate-3)] data-[state=open]:bg-[var(--slate-3)] data-[state=open]:border-border rounded px-2 -mx-2",
+ "group flex items-center my-1 space-between w-full select-none gap-2 border hover:border-border border-transparent hover:bg-[var(--slate-3)] data-[state=open]:bg-[var(--slate-3)] data-[state=open]:border-border rounded px-2 -mx-2",
className,
)}
data-testid="data-table-sort-button"
@@ -108,7 +108,7 @@ export const DataTableColumnHeaderWithSummary = <TData, TValue>({
return (
<div
className={cn(
- "flex flex-col h-full py-2 justify-between items-start gap-1",
+ "flex flex-col h-full py-1 justify-between items-start gap-1",
className,
)}
>
diff --git a/frontend/src/components/data-table/columns.tsx b/frontend/src/components/data-table/columns.tsx
index 025f91581f..49f1cde2a0 100644
--- a/frontend/src/components/data-table/columns.tsx
+++ b/frontend/src/components/data-table/columns.tsx
@@ -60,11 +60,17 @@ function getColumnInfo<T>(items: T[]): ColumnInfo[] {
return [...keys.values()];
}
-export function generateColumns<T>(
- items: T[],
- rowHeaders: Array<ColumnDef<T>>,
- selection: "single" | "multi" | null,
-): Array<ColumnDef<T>> {
+export function generateColumns<T>({
+ items,
+ rowHeaders,
+ selection,
+ showColumnSummaries,
+}: {
+ items: T[];
+ rowHeaders: Array<ColumnDef<T>>;
+ selection: "single" | "multi" | null;
+ showColumnSummaries: boolean;
+}): Array<ColumnDef<T>> {
const columnInfo = getColumnInfo(items);
const columns = columnInfo.map(
@@ -78,6 +84,10 @@ export function generateColumns<T>(
return (row as any)[info.key];
},
header: ({ column }) => {
+ if (!showColumnSummaries) {
+ return <DataTableColumnHeader header={info.key} column={column} />;
+ }
+
return (
<DataTableColumnHeaderWithSummary
header={info.key}
diff --git a/frontend/src/components/data-table/data-table.tsx b/frontend/src/components/data-table/data-table.tsx
index 4233df3aa5..951858d612 100644
--- a/frontend/src/components/data-table/data-table.tsx
+++ b/frontend/src/components/data-table/data-table.tsx
@@ -33,7 +33,6 @@ interface DataTableProps<TData> extends Partial<DownloadActionProps> {
pagination?: boolean;
pageSize?: number;
selection?: "single" | "multi" | null;
- showColumnSummary?: boolean;
rowSelection?: RowSelectionState;
onRowSelectionChange?: OnChangeFn<RowSelectionState>;
}
@@ -86,7 +85,7 @@ const DataTableInternal = <TData,>({
return (
<TableHead
key={header.id}
- className="h-auto min-h-10 whitespace-nowrap"
+ className="h-auto min-h-10 whitespace-nowrap align-baseline"
>
{header.isPlaceholder
? null
diff --git a/frontend/src/components/editor/file-tree/file-viewer.tsx b/frontend/src/components/editor/file-tree/file-viewer.tsx
index 66b90507bb..c0e56613f2 100644
--- a/frontend/src/components/editor/file-tree/file-viewer.tsx
+++ b/frontend/src/components/editor/file-tree/file-viewer.tsx
@@ -224,7 +224,16 @@ export const FileViewer: React.FC<Props> = ({ file }) => {
const CsvViewer: React.FC<{ contents: string }> = ({ contents }) => {
const data = useMemo(() => parseCsvData(contents), [contents]);
- const columns = useMemo(() => generateColumns(data, [], null), [data]);
+ const columns = useMemo(
+ () =>
+ generateColumns({
+ items: data,
+ rowHeaders: [],
+ selection: null,
+ showColumnSummaries: false,
+ }),
+ [data],
+ );
return (
<DataTable
diff --git a/frontend/src/plugins/impl/DataTablePlugin.tsx b/frontend/src/plugins/impl/DataTablePlugin.tsx
index 8ced77f53f..153ae3e27a 100644
--- a/frontend/src/plugins/impl/DataTablePlugin.tsx
+++ b/frontend/src/plugins/impl/DataTablePlugin.tsx
@@ -39,7 +39,7 @@ interface Data<T> {
pageSize: number;
selection: "single" | "multi" | null;
showDownload: boolean;
- showColumnSummary: boolean;
+ showColumnSummaries: boolean;
rowHeaders: Array<[string, string[]]>;
fieldTypes?: Record<string, VegaType> | null;
}
@@ -66,7 +66,7 @@ export const DataTablePlugin = createPlugin<S>("marimo-table")
pageSize: z.number().default(10),
selection: z.enum(["single", "multi"]).nullable().default(null),
showDownload: z.boolean().default(false),
- showColumnSummary: z.boolean().default(true),
+ showColumnSummaries: z.boolean().default(true),
rowHeaders: z.array(z.tuple([z.string(), z.array(z.any())])),
fieldTypes: z
.record(
@@ -191,7 +191,7 @@ const DataTableComponent = ({
value,
showDownload,
rowHeaders,
- showColumnSummary,
+ showColumnSummaries,
fieldTypes,
download_as: downloadAs,
columnSummaries,
@@ -212,8 +212,14 @@ const DataTableComponent = ({
});
}, [data, fieldTypes, columnSummaries, resultsAreClipped]);
const columns = useMemo(
- () => generateColumns(data, generateIndexColumns(rowHeaders), selection),
- [data, selection, rowHeaders],
+ () =>
+ generateColumns({
+ items: data,
+ rowHeaders: generateIndexColumns(rowHeaders),
+ selection,
+ showColumnSummaries: showColumnSummaries,
+ }),
+ [data, selection, rowHeaders, showColumnSummaries],
);
const rowSelection = Object.fromEntries((value || []).map((v) => [v, true]));
@@ -235,7 +241,6 @@ const DataTableComponent = ({
pageSize={pageSize}
rowSelection={rowSelection}
downloadAs={showDownload ? downloadAs : undefined}
- showColumnSummary={showColumnSummary}
onRowSelectionChange={(updater) => {
if (selection === "single") {
const nextValue =
diff --git a/frontend/src/plugins/impl/data-frames/DataFramePlugin.tsx b/frontend/src/plugins/impl/data-frames/DataFramePlugin.tsx
index 752438e1a2..fece11f0a1 100644
--- a/frontend/src/plugins/impl/data-frames/DataFramePlugin.tsx
+++ b/frontend/src/plugins/impl/data-frames/DataFramePlugin.tsx
@@ -168,7 +168,7 @@ export const DataFrameComponent = memo(
rowHeaders={row_headers || Arrays.EMPTY}
showDownload={false}
download_as={Functions.THROW}
- showColumnSummary={false}
+ showColumnSummaries={false}
get_column_summaries={getColumnSummaries}
value={Arrays.EMPTY}
setValue={Functions.NOOP}
diff --git a/frontend/src/stories/data-table.stories.tsx b/frontend/src/stories/data-table.stories.tsx
index d4b5a6cc5c..46bd009607 100644
--- a/frontend/src/stories/data-table.stories.tsx
+++ b/frontend/src/stories/data-table.stories.tsx
@@ -20,8 +20,8 @@ export const Default = {
last_name: "Schrute",
},
]}
- columns={generateColumns(
- [
+ columns={generateColumns({
+ items: [
{
first_name: "Michael",
last_name: "Scott",
@@ -31,9 +31,10 @@ export const Default = {
last_name: "Schrute",
},
],
- [],
- null,
- )}
+ rowHeaders: [],
+ selection: null,
+ showColumnSummaries: false,
+ })}
/>
),
@@ -44,8 +45,8 @@ export const Empty1 = {
render: () => (
<DataTable
data={[]}
- columns={generateColumns(
- [
+ columns={generateColumns({
+ items: [
{
first_name: "Michael",
last_name: "Scott",
@@ -55,9 +56,10 @@ export const Empty1 = {
last_name: "Schrute",
},
],
- [],
- null,
- )}
+ rowHeaders: [],
+ selection: null,
+ showColumnSummaries: false,
+ })}
/>
),
@@ -82,8 +84,8 @@ export const Pagination = {
last_name: "Schrute",
},
]}
- columns={generateColumns(
- [
+ columns={generateColumns({
+ items: [
{
first_name: "Michael",
last_name: "Scott",
@@ -93,9 +95,10 @@ export const Pagination = {
last_name: "Schrute",
},
],
- [],
- null,
- )}
+ rowHeaders: [],
+ selection: null,
+ showColumnSummaries: false,
+ })}
pagination={true}
/>
),
diff --git a/marimo/_plugins/ui/_impl/table.py b/marimo/_plugins/ui/_impl/table.py
index afed57d661..77dfe71852 100644
--- a/marimo/_plugins/ui/_impl/table.py
+++ b/marimo/_plugins/ui/_impl/table.py
@@ -134,10 +134,11 @@ class table(
- as a single column: a list of values
- `pagination`: whether to paginate; if `False`, all rows will be shown
defaults to `True` when above 10 rows, `False` otherwise
- - `page_size`: the number of rows to show per page.
- defaults to 10
- `selection`: 'single' or 'multi' to enable row selection, or `None` to
disable
+ - `page_size`: the number of rows to show per page.
+ defaults to 10
+ - `show_column_summaries`: whether to show column summaries
- `label`: text label for the element
- `on_change`: optional callback to run when this element's value changes
"""
@@ -157,6 +158,7 @@ class table(
pagination: Optional[bool] = None,
selection: Optional[Literal["single", "multi"]] = "multi",
page_size: int = 10,
+ show_column_summaries: bool = True,
*,
label: str = "",
on_change: Optional[
@@ -205,6 +207,7 @@ class table(
if self._manager.supports_selection()
else None,
"show-download": self._manager.supports_download(),
+ "show-column-summaries": show_column_summaries,
"row-headers": self._manager.get_row_headers(),
},
on_change=on_change,