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.

feat: Build plots and charts from tables, with Python code generation (#5452)

Shahmir Varqhaa522ca690976
diff --git a/frontend/src/components/app-config/user-config-form.tsx b/frontend/src/components/app-config/user-config-form.tsx
index 394b0eac45..cbf47d77c6 100644
--- a/frontend/src/components/app-config/user-config-form.tsx
+++ b/frontend/src/components/app-config/user-config-form.tsx
@@ -1442,28 +1442,6 @@ export const UserConfigForm: React.FC = () => {
</div>
)}
/>
- <FormField
- control={form.control}
- name="experimental.table_charts"
- render={({ field }) => (
- <div className="flex flex-col gap-y-1">
- <FormItem className={formItemClasses}>
- <FormLabel className="font-normal">Table Charts</FormLabel>
- <FormControl>
- <Checkbox
- data-testid="data-table-plugin-checkbox"
- checked={field.value === true}
- onCheckedChange={field.onChange}
- />
- </FormControl>
- </FormItem>
- <FormDescription>
- Enable experimental charting feature on tables. Data is
- saved in local storage. May not be performant.
- </FormDescription>
- </div>
- )}
- />
<FormField
control={form.control}
name="experimental.rtc_v2"
diff --git a/frontend/src/components/data-table/TableActions.tsx b/frontend/src/components/data-table/TableActions.tsx
index 8466b4a9a9..50773b3b99 100644
--- a/frontend/src/components/data-table/TableActions.tsx
+++ b/frontend/src/components/data-table/TableActions.tsx
@@ -3,8 +3,8 @@
import type { RowSelectionState, Table } from "@tanstack/react-table";
import {
- ChartAreaIcon,
ChartColumnStacked,
+ ChartSplineIcon,
PanelRightIcon,
SearchIcon,
} from "lucide-react";
@@ -32,7 +32,9 @@ interface TableActionsProps<TData> {
downloadAs?: DownloadActionProps["downloadAs"];
getRowIds?: GetRowIds;
toggleDisplayHeader?: () => void;
- chartsFeatureEnabled?: boolean;
+ showChartBuilder?: boolean;
+ showColumnExplorer?: boolean;
+ showPageSizeSelector?: boolean;
togglePanel?: (panelType: PanelType) => void;
isPanelOpen?: (panelType: PanelType) => boolean;
tableLoading?: boolean;
@@ -51,7 +53,9 @@ export const TableActions = <TData,>({
downloadAs,
getRowIds,
toggleDisplayHeader,
- chartsFeatureEnabled,
+ showChartBuilder,
+ showColumnExplorer,
+ showPageSizeSelector,
togglePanel,
isPanelOpen,
tableLoading,
@@ -114,15 +118,15 @@ export const TableActions = <TData,>({
</Button>
</Tooltip>
)}
- {chartsFeatureEnabled && (
- <Tooltip content="Show charts">
+ {showChartBuilder && (
+ <Tooltip content="Chart builder">
<Button
variant="text"
size="xs"
className="mb-0"
onClick={toggleDisplayHeader}
>
- <ChartAreaIcon className="w-4 h-4 text-muted-foreground" />
+ <ChartSplineIcon className="w-4 h-4 text-muted-foreground" />
</Button>
</Tooltip>
)}
@@ -142,20 +146,22 @@ export const TableActions = <TData,>({
/>
</Button>
</Tooltip>
- <Tooltip content="Toggle column explorer">
- <Button
- variant="text"
- size="xs"
- onClick={() => togglePanel("column-explorer")}
- >
- <ChartColumnStacked
- className={cn(
- "w-4 h-4 text-muted-foreground",
- isPanelOpen("column-explorer") && "text-primary",
- )}
- />
- </Button>
- </Tooltip>
+ {showColumnExplorer && (
+ <Tooltip content="Toggle column explorer">
+ <Button
+ variant="text"
+ size="xs"
+ onClick={() => togglePanel("column-explorer")}
+ >
+ <ChartColumnStacked
+ className={cn(
+ "w-4 h-4 text-muted-foreground",
+ isPanelOpen("column-explorer") && "text-primary",
+ )}
+ />
+ </Button>
+ </Tooltip>
+ )}
</>
)}
@@ -166,6 +172,7 @@ export const TableActions = <TData,>({
onSelectAllRowsChange={handleSelectAllRows}
table={table}
tableLoading={tableLoading}
+ showPageSizeSelector={showPageSizeSelector}
/>
)}
<div className="ml-auto">
diff --git a/frontend/src/components/data-table/charts/charts.tsx b/frontend/src/components/data-table/charts/charts.tsx
index e86f7085d4..35082459ee 100644
--- a/frontend/src/components/data-table/charts/charts.tsx
+++ b/frontend/src/components/data-table/charts/charts.tsx
@@ -8,7 +8,6 @@ import {
ChevronRightIcon,
CodeIcon,
DatabaseIcon,
- InfoIcon,
PaintRollerIcon,
XIcon,
} from "lucide-react";
@@ -20,7 +19,6 @@ import { PythonIcon } from "@/components/editor/cell/code/icons";
import { Button } from "@/components/ui/button";
import { Form } from "@/components/ui/form";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
-import { Tooltip } from "@/components/ui/tooltip";
import type { CellId } from "@/core/cells/ids";
import { useAsyncData } from "@/hooks/useAsyncData";
import { useDebouncedCallback } from "@/hooks/useDebounce";
@@ -222,6 +220,8 @@ export const TablePanel: React.FC<TablePanelProps> = ({
);
};
+const CHART_PLACEHOLDER_CODE = "X and Y columns are not set";
+
export const ChartPanel: React.FC<{
chartConfig: ChartSchemaType | null;
chartType: ChartType;
@@ -304,7 +304,7 @@ export const ChartPanel: React.FC<{
const developmentMode = import.meta.env.DEV;
const renderChartDisplay = () => {
- let altairCodeSnippet = "X and Y columns are not set";
+ let altairCodeSnippet = CHART_PLACEHOLDER_CODE;
if (typeof specWithoutData !== "string") {
altairCodeSnippet = generateAltairChartSnippet(
specWithoutData,
@@ -338,16 +338,17 @@ export const ChartPanel: React.FC<{
</>
)}
</TabsList>
- <Tooltip content="Charts are saved in local storage but as it remains experimental, we encourage saving the generated Python code in a new cell">
- <InfoIcon className="w-4 h-4 text-muted-foreground" />
- </Tooltip>
</div>
<TabsContent value="chart" ref={chartContainerRef}>
{memoizedChart}
</TabsContent>
<TabsContent value="code">
- <CodeSnippet code={altairCodeSnippet} language="python" />
+ <CodeSnippet
+ code={altairCodeSnippet}
+ insertNewCell={altairCodeSnippet !== CHART_PLACEHOLDER_CODE}
+ language="python"
+ />
</TabsContent>
{developmentMode && (
<>
@@ -397,14 +398,14 @@ export const ChartPanel: React.FC<{
<Button
variant="outline"
size="icon"
- className="absolute bottom-1 right-1 border-border"
+ className="border-border ml-auto"
onClick={() => setFormCollapsed((prev) => !prev)}
title={formCollapsed ? "Expand sidebar" : "Collapse sidebar"}
>
{formCollapsed ? (
- <ChevronRightIcon className="w-4 h-4" />
+ <ChevronRightIcon className="w-4 h-5" />
) : (
- <ChevronLeftIcon className="w-4 h-4" />
+ <ChevronLeftIcon className="w-4 h-5" />
)}
</Button>
</div>
diff --git a/frontend/src/components/data-table/charts/components/layouts.tsx b/frontend/src/components/data-table/charts/components/layouts.tsx
index abc4d92196..213cfa223c 100644
--- a/frontend/src/components/data-table/charts/components/layouts.tsx
+++ b/frontend/src/components/data-table/charts/components/layouts.tsx
@@ -101,8 +101,9 @@ export const AccordionFormContent: React.FC<{
export const CodeSnippet: React.FC<{
code: string;
+ insertNewCell?: boolean;
language?: "python" | "sql";
-}> = ({ code, language }) => {
+}> = ({ code, insertNewCell, language }) => {
return (
<ReadonlyCode
minHeight="330px"
@@ -111,7 +112,7 @@ export const CodeSnippet: React.FC<{
language={language}
showHideCode={false}
showCopyCode={false}
- insertNewCell={true}
+ insertNewCell={insertNewCell}
/>
);
};
diff --git a/frontend/src/components/data-table/charts/forms/common-chart.tsx b/frontend/src/components/data-table/charts/forms/common-chart.tsx
index b43fa7fdee..9aee753756 100644
--- a/frontend/src/components/data-table/charts/forms/common-chart.tsx
+++ b/frontend/src/components/data-table/charts/forms/common-chart.tsx
@@ -1,9 +1,10 @@
/* Copyright 2024 Marimo. All rights reserved. */
import { capitalize } from "lodash-es";
-import { InfoIcon } from "lucide-react";
+import { InfoIcon, TriangleAlert } from "lucide-react";
import { useFormContext, useWatch } from "react-hook-form";
import { Accordion } from "@/components/ui/accordion";
+import { Tooltip } from "@/components/ui/tooltip";
import { isFieldSet } from "../chart-spec/spec";
import { ColorByAxis, Facet, XAxis, YAxis } from "../components/chart-items";
import {
@@ -43,6 +44,16 @@ export const CommonChartForm: React.FC = () => {
return (
<>
+ <Tooltip
+ delayDuration={100}
+ content="To persist a chart, add the generated Python code to a new cell."
+ >
+ <div className="flex items-center gap-1">
+ <TriangleAlert className="h-3.5 w-3.5 mb-0.5 text-muted-foreground" />
+ <p className="text-sm text-muted-foreground">Charts are not saved.</p>
+ </div>
+ </Tooltip>
+
<XAxis />
<YAxis />
diff --git a/frontend/src/components/data-table/data-table.tsx b/frontend/src/components/data-table/data-table.tsx
index 5696c241d4..dc2c0e38a9 100644
--- a/frontend/src/components/data-table/data-table.tsx
+++ b/frontend/src/components/data-table/data-table.tsx
@@ -82,7 +82,9 @@ interface DataTableProps<TData> extends Partial<DownloadActionProps> {
viewedRowIdx?: number;
onViewedRowChange?: OnChangeFn<number>;
// Others
- chartsFeatureEnabled?: boolean;
+ showChartBuilder?: boolean;
+ showPageSizeSelector?: boolean;
+ showColumnExplorer?: boolean;
togglePanel?: (panelType: PanelType) => void;
isPanelOpen?: (panelType: PanelType) => boolean;
}
@@ -119,7 +121,9 @@ const DataTableInternal = <TData,>({
freezeColumnsLeft,
freezeColumnsRight,
toggleDisplayHeader,
- chartsFeatureEnabled,
+ showChartBuilder,
+ showPageSizeSelector,
+ showColumnExplorer,
togglePanel,
isPanelOpen,
viewedRowIdx,
@@ -153,7 +157,7 @@ const DataTableInternal = <TData,>({
}, [reloading]);
// Returns the row index, accounting for pagination
- function getPaginatedRowIndex(row: TData, idx: number): number {
+ function getPaginatedRowIndex(_row: TData, idx: number): number {
if (!paginationState) {
return idx;
}
@@ -280,7 +284,9 @@ const DataTableInternal = <TData,>({
downloadAs={downloadAs}
getRowIds={getRowIds}
toggleDisplayHeader={toggleDisplayHeader}
- chartsFeatureEnabled={chartsFeatureEnabled}
+ showChartBuilder={showChartBuilder}
+ showPageSizeSelector={showPageSizeSelector}
+ showColumnExplorer={showColumnExplorer}
togglePanel={togglePanel}
isPanelOpen={isPanelOpen}
tableLoading={reloading}
diff --git a/frontend/src/components/data-table/pagination.tsx b/frontend/src/components/data-table/pagination.tsx
index 096448e5e6..b8698232eb 100644
--- a/frontend/src/components/data-table/pagination.tsx
+++ b/frontend/src/components/data-table/pagination.tsx
@@ -29,6 +29,7 @@ interface DataTablePaginationProps<TData> {
totalColumns: number;
onSelectAllRowsChange?: (value: boolean) => void;
tableLoading?: boolean;
+ showPageSizeSelector?: boolean;
}
export const DataTablePagination = <TData,>({
@@ -37,6 +38,7 @@ export const DataTablePagination = <TData,>({
onSelectAllRowsChange,
totalColumns,
tableLoading,
+ showPageSizeSelector,
}: DataTablePaginationProps<TData>) => {
const renderTotal = () => {
const { rowSelection, cellSelection } = table.getState();
@@ -116,10 +118,6 @@ export const DataTablePagination = <TData,>({
const pageSize = table.getState().pagination.pageSize;
- // Ensure unique page sizes
- const pageSizeSet = new Set([5, 10, 25, 50, 100, pageSize]);
- const pageSizes = [...pageSizeSet].sort((a, b) => a - b);
-
const handlePageChange = (pageChangeFn: () => void) => {
// Frequent page changes can reset the page index, so we wait until the previous change has completed
if (!tableLoading) {
@@ -127,34 +125,44 @@ export const DataTablePagination = <TData,>({
}
};
+ // Ensure unique page sizes
+ const pageSizeSet = new Set([5, 10, 25, 50, 100, pageSize]);
+ const pageSizes = [...pageSizeSet].sort((a, b) => a - b);
+
+ const renderPageSizeSelector = () => {
+ return (
+ <div className="flex items-center gap-1 text-xs whitespace-nowrap mr-1">
+ <Select
+ value={pageSize.toString()}
+ onValueChange={(value) => table.setPageSize(Number(value))}
+ >
+ <SelectTrigger className="w-11 h-[18px] !shadow-none !hover:shadow-none !ring-0 border-border text-xs p-1">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectGroup>
+ <SelectLabel>Rows per page</SelectLabel>
+ {[...pageSizes].map((size) => {
+ const sizeStr = size.toString();
+ return (
+ <SelectItem key={size} value={sizeStr}>
+ {sizeStr}
+ </SelectItem>
+ );
+ })}
+ </SelectGroup>
+ </SelectContent>
+ </Select>
+ <span>/ page</span>
+ </div>
+ );
+ };
+
return (
<div className="flex flex-1 items-center justify-between px-2">
<div className="flex items-center gap-2">
<div className="text-sm text-muted-foreground">{renderTotal()}</div>
- <div className="flex items-center gap-1 text-xs whitespace-nowrap mr-1">
- <Select
- value={pageSize.toString()}
- onValueChange={(value) => table.setPageSize(Number(value))}
- >
- <SelectTrigger className="w-11 h-[18px] !shadow-none !hover:shadow-none !ring-0 border-border text-xs p-1">
- <SelectValue />
- </SelectTrigger>
- <SelectContent>
- <SelectGroup>
- <SelectLabel>Rows per page</SelectLabel>
- {[...pageSizes].map((size) => {
- const sizeStr = size.toString();
- return (
- <SelectItem key={size} value={sizeStr}>
- {sizeStr}
- </SelectItem>
- );
- })}
- </SelectGroup>
- </SelectContent>
- </Select>
- <span>/ page</span>
- </div>
+ {showPageSizeSelector && renderPageSizeSelector()}
</div>
<div className="flex items-end space-x-2">
diff --git a/frontend/src/core/config/feature-flag.tsx b/frontend/src/core/config/feature-flag.tsx
index 3db7e1dec1..c7d90601ab 100644
--- a/frontend/src/core/config/feature-flag.tsx
+++ b/frontend/src/core/config/feature-flag.tsx
@@ -11,7 +11,6 @@ export interface ExperimentalFeatures {
inline_ai_tooltip: boolean;
wasm_layouts: boolean; // Used in playground (community cloud)
rtc_v2: boolean;
- table_charts: boolean;
// Add new feature flags here
}
@@ -20,7 +19,6 @@ const defaultValues: ExperimentalFeatures = {
inline_ai_tooltip: import.meta.env.DEV,
wasm_layouts: false,
rtc_v2: false,
- table_charts: false,
};
export function getFeatureFlag<T extends keyof ExperimentalFeatures>(
diff --git a/frontend/src/plugins/impl/DataTablePlugin.tsx b/frontend/src/plugins/impl/DataTablePlugin.tsx
index fb90003fc6..ed28deac41 100644
--- a/frontend/src/plugins/impl/DataTablePlugin.tsx
+++ b/frontend/src/plugins/impl/DataTablePlugin.tsx
@@ -52,7 +52,6 @@ import { Alert, AlertTitle } from "@/components/ui/alert";
import { Button } from "@/components/ui/button";
import { DelayMount } from "@/components/utils/delay-mount";
import { type CellId, findCellId } from "@/core/cells/ids";
-import { getFeatureFlag } from "@/core/config/feature-flag";
import { DATA_TYPES } from "@/core/kernel/messages";
import { slotsController } from "@/core/slots/slots";
import { store } from "@/core/state/jotai";
@@ -146,6 +145,9 @@ interface Data<T> {
showDownload: boolean;
showFilters: boolean;
showColumnSummaries: boolean | "stats" | "chart";
+ showPageSizeSelector: boolean;
+ showColumnExplorer: boolean;
+ showChartBuilder: boolean;
rowHeaders: string[];
fieldTypes?: FieldTypesWithExternalType | null;
freezeColumnsLeft?: string[];
@@ -206,6 +208,9 @@ export const DataTablePlugin = createPlugin<S>("marimo-table")
showColumnSummaries: z
.union([z.boolean(), z.enum(["stats", "chart"])])
.default(true),
+ showPageSizeSelector: z.boolean().default(true),
+ showColumnExplorer: z.boolean().default(true),
+ showChartBuilder: z.boolean().default(true),
rowHeaders: z.array(z.string()),
freezeColumnsLeft: z.array(z.string()).optional(),
freezeColumnsRight: z.array(z.string()).optional(),
@@ -312,7 +317,6 @@ export const DataTablePlugin = createPlugin<S>("marimo-table")
data={props.data.data}
value={props.value}
setValue={props.setValue}
- experimentalChartsEnabled={true}
/>
</LazyDataTableComponent>
</TableProviders>
@@ -353,9 +357,7 @@ interface DataTableProps<T> extends Data<T>, DataTableFunctions {
// Filters
enableFilters?: boolean;
cellStyles?: CellStyleState | null;
- experimentalChartsEnabled?: boolean;
toggleDisplayHeader?: () => void;
- chartsFeatureEnabled?: boolean;
host: HTMLElement;
cellId?: CellId | null;
}
@@ -398,7 +400,7 @@ export const LoadingDataTableComponent = memo(
const [filters, setFilters] = useState<ColumnFiltersState>([]);
const [displayHeader, setDisplayHeader] = useState(() => {
// Show the header if a single chart is configured
- if (!getFeatureFlag("table_charts") || !cellId) {
+ if (!props.showChartBuilder || !cellId) {
return false;
}
return hasChart(cellId);
@@ -594,9 +596,6 @@ export const LoadingDataTableComponent = memo(
setDisplayHeader(!displayHeader);
};
- const chartsFeatureEnabled =
- getFeatureFlag("table_charts") && props.experimentalChartsEnabled;
-
const dataTable = (
<DataTableComponent
{...props}
@@ -614,7 +613,6 @@ export const LoadingDataTableComponent = memo(
setPaginationState={setPaginationState}
cellStyles={data?.cellStyles ?? props.cellStyles}
toggleDisplayHeader={toggleDisplayHeader}
- chartsFeatureEnabled={chartsFeatureEnabled}
getRow={getRow}
cellId={cellId}
/>
@@ -623,7 +621,7 @@ export const LoadingDataTableComponent = memo(
return (
<>
{errorComponent}
- {chartsFeatureEnabled ? (
+ {props.showChartBuilder ? (
<TablePanel
displayHeader={displayHeader}
dataTable={dataTable}
@@ -650,6 +648,9 @@ const DataTableComponent = ({
value,
showFilters,
showDownload,
+ showPageSizeSelector,
+ showColumnExplorer,
+ showChartBuilder,
rowHeaders,
fieldTypes,
paginationState,
@@ -674,7 +675,6 @@ const DataTableComponent = ({
get_row_ids,
cellStyles,
toggleDisplayHeader,
- chartsFeatureEnabled,
calculate_top_k_rows,
preview_column,
getRow,
@@ -790,6 +790,8 @@ const DataTableComponent = ({
);
const isSelectable = selection === "multi" || selection === "single";
+ const showColExplorer =
+ showColumnExplorer && preview_column && isPanelOpen("column-explorer");
return (
<>
@@ -830,7 +832,7 @@ const DataTableComponent = ({
/>
</ContextAwarePanelItem>
)}
- {isPanelOpen("column-explorer") && preview_column && (
+ {showColExplorer && (
<ContextAwarePanelItem>
<ColumnExplorerPanel
previewColumn={preview_column}
@@ -875,7 +877,9 @@ const DataTableComponent = ({
onCellSelectionChange={handleCellSelectionChange}
getRowIds={get_row_ids}
toggleDisplayHeader={toggleDisplayHeader}
- chartsFeatureEnabled={chartsFeatureEnabled}
+ showChartBuilder={showChartBuilder}
+ showPageSizeSelector={showPageSizeSelector}
+ showColumnExplorer={showColumnExplorer}
togglePanel={togglePanel}
isPanelOpen={isPanelOpen}
viewedRowIdx={viewedRowIdx}
diff --git a/frontend/src/plugins/impl/data-frames/DataFramePlugin.tsx b/frontend/src/plugins/impl/data-frames/DataFramePlugin.tsx
index 4f24e1dcbd..514bd73112 100644
--- a/frontend/src/plugins/impl/data-frames/DataFramePlugin.tsx
+++ b/frontend/src/plugins/impl/data-frames/DataFramePlugin.tsx
@@ -279,6 +279,9 @@ export const DataFrameComponent = memo(
search={search}
showColumnSummaries={false}
get_column_summaries={getColumnSummaries}
+ showPageSizeSelector={(total_rows && total_rows > 5) || false}
+ showColumnExplorer={false}
+ showChartBuilder={false}
value={Arrays.EMPTY}
setValue={Functions.NOOP}
selection={null}
diff --git a/marimo/_plugins/ui/_impl/table.py b/marimo/_plugins/ui/_impl/table.py
index 7d730dc30a..478e4e7b54 100644
--- a/marimo/_plugins/ui/_impl/table.py
+++ b/marimo/_plugins/ui/_impl/table.py
@@ -57,6 +57,7 @@ from marimo._runtime.context.types import (
ContextNotInitializedError,
get_context,
)
+from marimo._runtime.context.utils import get_mode
from marimo._runtime.functions import EmptyArgs, Function
from marimo._utils.hashable import is_hashable
from marimo._utils.narwhals_utils import (
@@ -473,6 +474,15 @@ class table(
TableManager.DEFAULT_SUMMARY_STATS_ROW_LIMIT
)
+ app_mode = get_mode()
+ # These panels are not as useful in non-edit mode and require an external dependency
+ show_column_explorer = app_mode == "edit"
+ show_chart_builder = app_mode == "edit"
+
+ show_page_size_selector = True
+ if (isinstance(total_rows, int) and total_rows <= 5) or _internal_lazy:
+ show_page_size_selector = False
+
# Holds the data after user searching from original data
# (searching operations include query, sort, filter, etc.)
self._searched_manager = self._manager
@@ -602,6 +612,9 @@ class table(
"show-download": show_download
and self._manager.supports_download(),
"show-column-summaries": show_column_summaries,
+ "show-page-size-selector": show_page_size_selector,
+ "show-column-explorer": show_column_explorer,
+ "show-chart-builder": show_chart_builder,
"row-headers": self._manager.get_row_headers(),
"freeze-columns-left": freeze_columns_left,
"freeze-columns-right": freeze_columns_right,
diff --git a/tests/_plugins/ui/_impl/test_table.py b/tests/_plugins/ui/_impl/test_table.py
index 88d56b9658..1a7bed7d4e 100644
--- a/tests/_plugins/ui/_impl/test_table.py
+++ b/tests/_plugins/ui/_impl/test_table.py
@@ -4,6 +4,7 @@ from __future__ import annotations
import json
from datetime import date
from typing import TYPE_CHECKING, Any
+from unittest.mock import patch
import pytest
@@ -979,6 +980,7 @@ def test_show_column_summaries_modes():
assert summaries_default.is_disabled is False
assert summaries_default.data is not None
assert len(summaries_default.stats) > 0
+ assert table_default._component_args["show-column-summaries"] is True
def test_table_with_frozen_columns() -> None:
@@ -1046,7 +1048,6 @@ def test_show_column_summaries_default():
# explicitly set to True
table_true = ui.table(large_data, show_column_summaries=True)
assert table_true._show_column_summaries is True
- assert table_true._component_args["show-column-summaries"] is True
def test_data_with_rich_components():
@@ -1712,6 +1713,9 @@ def test_lazy_dataframe() -> None:
assert table._component_args["total-columns"] == 0
assert table._component_args["max-columns"] == DEFAULT_MAX_COLUMNS
assert table._component_args["field-types"] is None
+ assert table._component_args["show-page-size-selector"] is False
+ assert table._component_args["show-column-explorer"] is False
+ assert table._component_args["show-chart-builder"] is False
# Verify that search response indicates "too_many" for total_rows
# but returns the preview rows
@@ -1952,3 +1956,31 @@ def test_max_columns_not_provided_with_filters():
response = table._search(search_args)
result_data = json.loads(response.data)
assert len(result_data[0].keys()) == 101 # +1 for marimo_row_id
+
+
+def test_show_page_size_selector_property():
+ """Test the show_page_size_selector property behavior."""
+ data = {"a": list(range(20))} # 20 rows to ensure pagination
+
+ # Test default behavior
+ table_default = ui.table(data)
+ assert table_default._component_args["show-page-size-selector"] is True
+
+ # Test with small dataset (should disable automatically)
+ small_data = {"a": [1, 2, 3, 4]} # Less than 5 rows
+ table_small = ui.table(small_data)
+ assert table_small._component_args["show-page-size-selector"] is False
+
+
+def test_show_toggles_app_mode():
+ data = {"a": [1, 2, 3], "b": [4, 5, 6]}
+
+ with patch("marimo._plugins.ui._impl.table.get_mode", return_value="edit"):
+ table_default = ui.table(data)
+ assert table_default._component_args["show-column-explorer"] is True
+ assert table_default._component_args["show-chart-builder"] is True
+
+ with patch("marimo._plugins.ui._impl.table.get_mode", return_value="run"):
+ table_default = ui.table(data)
+ assert table_default._component_args["show-column-explorer"] is False
+ assert table_default._component_args["show-chart-builder"] is False