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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
improvement: row viewer improvements, and add to docs (#4992)
Shahmir Varqha914933100d80
diff --git a/docs/_static/docs-row-viewer-panel.gif b/docs/_static/docs-row-viewer-panel.gifnew file mode 100644index 0000000000..94d75368cfBinary files /dev/null and b/docs/_static/docs-row-viewer-panel.gif differdiff --git a/docs/guides/working_with_data/dataframes.md b/docs/guides/working_with_data/dataframes.mdindex 9cc7756c34..2b8e7116c9 100644--- a/docs/guides/working_with_data/dataframes.md+++ b/docs/guides/working_with_data/dataframes.md@@ -247,6 +247,19 @@ table.value///+## Row viewer panel++To inspect individual rows, you can toggle the Row viewer panel located at the bottom left of a table. While open, click on any row to view.++For convenience, you can pin the panel to the side of your editor or toggle the focused cell feature, which ensures the value of the currently focused cell is displayed in the panel.++<div align="center">+<figure>+<img src="/_static/docs-row-viewer-panel.gif" width="100%" height="100%" alt="Row viewer panel demonstration (click the bottom left of the table to toggle)">+<figcaption>Open the row viewer panel to display data vertically</figcaption>+</figure>+</div>+## Example notebookFor a comprehensive example of using Polars with marimo, check out our [Polars example notebook](https://github.com/marimo-team/marimo/blob/main/examples/third_party/polars/polars_example.py).diff --git a/frontend/src/components/data-table/data-table.tsx b/frontend/src/components/data-table/data-table.tsxindex f7b7a7675a..c361a1f8a2 100644--- a/frontend/src/components/data-table/data-table.tsx+++ b/frontend/src/components/data-table/data-table.tsx@@ -29,7 +29,7 @@ import { SearchBar } from "./SearchBar";import { TableActions } from "./TableActions";import { ColumnFormattingFeature } from "./column-formatting/feature";import { ColumnWrappingFeature } from "./column-wrapping/feature";-import type { DataTableSelection } from "./types";+import type { DataTableSelection, TooManyRows } from "./types";import { CellSelectionFeature } from "./cell-selection/feature";import type { CellSelectionState } from "./cell-selection/types";import type { GetRowIds } from "@/plugins/impl/DataTablePlugin";@@ -49,7 +49,7 @@ interface DataTableProps<TData> extends Partial<DownloadActionProps> {sorting?: SortingState; // controlled sortingsetSorting?: OnChangeFn<SortingState>; // controlled sorting// Pagination- totalRows: number | "too_many";+ totalRows: number | TooManyRows;totalColumns: number;pagination?: boolean;manualPagination?: boolean; // server-side paginationdiff --git a/frontend/src/components/data-table/row-viewer-panel/row-viewer.tsx b/frontend/src/components/data-table/row-viewer-panel/row-viewer.tsxindex db01b0d00c..d4300949c2 100644--- a/frontend/src/components/data-table/row-viewer-panel/row-viewer.tsx+++ b/frontend/src/components/data-table/row-viewer-panel/row-viewer.tsx@@ -26,6 +26,8 @@ import { useAsyncData } from "@/hooks/useAsyncData";import {INDEX_COLUMN_NAME,SELECT_COLUMN_ID,+ TOO_MANY_ROWS,+ type TooManyRows,type FieldTypesWithExternalType,} from "../types";import { prettifyRowCount } from "../pagination";@@ -39,7 +41,7 @@ import { useKeydownOnElement } from "@/hooks/useHotkey";export interface RowViewerPanelProps {rowIdx: number;setRowIdx: (rowIdx: number) => void;- totalRows: number;+ totalRows: number | TooManyRows;fieldTypes: FieldTypesWithExternalType | undefined | null;getRow: (rowIdx: number) => Promise<GetRowResult>;}@@ -55,18 +57,25 @@ export const RowViewerPanel: React.FC<RowViewerPanelProps> = ({const panelRef = useRef<HTMLDivElement>(null);const searchInputRef = useRef<HTMLInputElement>(null);+ const tooManyRows = totalRows === TOO_MANY_ROWS;+const { data: rows, error } = useAsyncData(async () => {const data = await getRow(rowIdx);return data.rows;}, [getRow, rowIdx, totalRows]);const handleSelectRow = (rowIdx: number) => {- if (rowIdx < 0 || rowIdx >= totalRows) {+ if (rowIdx < 0 || (typeof totalRows === "number" && rowIdx >= totalRows)) {return;}setRowIdx(rowIdx);};+ // Total rows may change after the row viewer panel is opened+ if (!tooManyRows && rowIdx > totalRows) {+ handleSelectRow(totalRows - 1);+ }+useKeydownOnElement(panelRef, {ArrowLeft: (e) => {if (e?.target === searchInputRef.current) {@@ -234,14 +243,16 @@ export const RowViewerPanel: React.FC<RowViewerPanelProps> = ({<ChevronLeft /></Button><span className="text-xs">- Row {rowIdx + 1} of {prettifyRowCount(totalRows)}+ {tooManyRows+ ? `Row ${rowIdx + 1}`+ : `Row ${rowIdx + 1} of ${prettifyRowCount(totalRows)}`}</span><Buttonvariant="outline"size="xs"className={buttonStyles}onClick={() => handleSelectRow(rowIdx + 1)}- disabled={rowIdx === totalRows - 1}+ disabled={!tooManyRows && rowIdx === totalRows - 1}aria-label="Next row"><ChevronRight />@@ -250,7 +261,12 @@ export const RowViewerPanel: React.FC<RowViewerPanelProps> = ({variant="outline"size="xs"className={buttonStyles}- onClick={() => handleSelectRow(totalRows - 1)}+ onClick={() => {+ if (!tooManyRows) {+ handleSelectRow(totalRows - 1);+ }+ }}+ disabled={tooManyRows || rowIdx === totalRows - 1}aria-label="Go to last row"><ChevronsRight />diff --git a/frontend/src/components/data-table/types.ts b/frontend/src/components/data-table/types.tsindex f35b340303..689ea3991b 100644--- a/frontend/src/components/data-table/types.ts+++ b/frontend/src/components/data-table/types.ts@@ -32,6 +32,9 @@ export const SELECT_COLUMN_ID = "__select__";export const INDEX_COLUMN_NAME = "_marimo_row_id";+export const TOO_MANY_ROWS = "too_many";+export type TooManyRows = typeof TOO_MANY_ROWS;+export type DataTableSelection =| "single"| "multi"diff --git a/frontend/src/components/editor/chrome/panels/context-aware-panel/context-aware-panel.tsx b/frontend/src/components/editor/chrome/panels/context-aware-panel/context-aware-panel.tsxindex c5ad54f2cd..cf098092ff 100644--- a/frontend/src/components/editor/chrome/panels/context-aware-panel/context-aware-panel.tsx+++ b/frontend/src/components/editor/chrome/panels/context-aware-panel/context-aware-panel.tsx@@ -41,12 +41,12 @@ export const ContextAwarePanel: React.FC = () => {const renderModeToggle = () => {return (<div className="flex flex-row items-center gap-2">- <Tooltip content={isPinned ? "Unpin" : "Pin"}>+ <Tooltip content={isPinned ? "Unpin panel" : "Pin panel"}><Togglesize="xs"onPressedChange={() => setIsPinned(!isPinned)}pressed={isPinned}- aria-label={isPinned ? "Unpin" : "Pin"}+ aria-label={isPinned ? "Unpin panel" : "Pin panel"}>{isPinned ? (<PinIcon className="w-4 h-4" />diff --git a/frontend/src/plugins/impl/DataTablePlugin.tsx b/frontend/src/plugins/impl/DataTablePlugin.tsxindex 907d55769f..297e8c71e5 100644--- a/frontend/src/plugins/impl/DataTablePlugin.tsx+++ b/frontend/src/plugins/impl/DataTablePlugin.tsx@@ -20,6 +20,8 @@ import {toFieldTypes,type ColumnHeaderSummary,type FieldTypesWithExternalType,+ type TooManyRows,+ TOO_MANY_ROWS,} from "@/components/data-table/types";import type {ColumnFiltersState,@@ -101,7 +103,7 @@ export interface GetRowResult {interface Data<T> {label: string | null;data: TableData<T>;- totalRows: number | "too_many";+ totalRows: number | TooManyRows;pagination: boolean;pageSize: number;selection: DataTableSelection;@@ -136,7 +138,7 @@ type DataTableFunctions = {max_columns?: number | null;}) => Promise<{data: TableData<T>;- total_rows: number | "too_many";+ total_rows: number | TooManyRows;cell_styles?: CellStyleState | null;}>;get_data_url?: GetDataUrl;@@ -155,7 +157,7 @@ export const DataTablePlugin = createPlugin<S>("marimo-table")]),label: z.string().nullable(),data: z.union([z.string(), z.array(z.object({}).passthrough())]),- totalRows: z.union([z.number(), z.literal("too_many")]),+ totalRows: z.union([z.number(), z.literal(TOO_MANY_ROWS)]),pagination: z.boolean().default(false),pageSize: z.number().default(10),selection: z@@ -232,7 +234,7 @@ export const DataTablePlugin = createPlugin<S>("marimo-table").output(z.object({data: z.union([z.string(), z.array(z.object({}).passthrough())]),- total_rows: z.union([z.number(), z.literal("too_many")]),+ total_rows: z.union([z.number(), z.literal(TOO_MANY_ROWS)]),cell_styles: z.record(z.record(z.object({}).passthrough())).nullable(),@@ -388,7 +390,7 @@ export const LoadingDataTableComponent = memo(// Data loadingconst { data, loading, error } = useAsyncData<{rows: T[];- totalRows: number | "too_many";+ totalRows: number | TooManyRows;cellStyles: CellStyleState | undefined | null;}>(async () => {// If there is no data, return an empty array@@ -531,7 +533,7 @@ export const LoadingDataTableComponent = memo(<DelayMount milliseconds={200}><LoadingTablepageSize={- props.totalRows !== "too_many" && props.totalRows > 0+ props.totalRows !== TOO_MANY_ROWS && props.totalRows > 0? props.totalRows: props.pageSize}@@ -758,11 +760,12 @@ const DataTableComponent = ({<>{/* When the totalRows is "too_many" and the pageSize is the same as the* number of rows, we are likely displaying all the data (could be more, but we don't know the total). */}- {totalRows === "too_many" && paginationState.pageSize === data.length && (- <Banner className="mb-1 rounded">- Previewing the first {paginationState.pageSize} rows.- </Banner>- )}+ {totalRows === TOO_MANY_ROWS &&+ paginationState.pageSize === data.length && (+ <Banner className="mb-1 rounded">+ Previewing the first {paginationState.pageSize} rows.+ </Banner>+ )}{shownColumns < totalColumns && shownColumns > 0 && (<Banner className="mb-1 rounded">Result clipped. Showing {shownColumns} of {totalColumns} columns.@@ -782,7 +785,7 @@ const DataTableComponent = ({<RowViewerPanelgetRow={getRow}fieldTypes={memoizedUnclampedFieldTypes}- totalRows={totalRows === "too_many" ? 100 : totalRows}+ totalRows={totalRows}rowIdx={focusedRowIdx}setRowIdx={setFocusedRowIdx}/>diff --git a/marimo/_runtime/watch/_file.py b/marimo/_runtime/watch/_file.pyindex 95f3367e1e..9bfdc3e9ac 100644--- a/marimo/_runtime/watch/_file.py+++ b/marimo/_runtime/watch/_file.py@@ -130,7 +130,7 @@ def file(path: Path | str) -> FileState:Warning:It is possible to misuse this API in similar ways to `state()`. Considerreading the warning and caveats in the- [`state()` documentation](../state), and using this function only when+ [`state()` documentation](state.md), and using this function only whenreading file paths, and not when writing them.Args: