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.

Add `expand_output` cell decorator (#10911)

Martha Cryan01417dcdf1be
diff --git a/frontend/src/__mocks__/notebook.ts b/frontend/src/__mocks__/notebook.ts
index 3c3263ebf2..ba2da0d26b 100644
--- a/frontend/src/__mocks__/notebook.ts
+++ b/frontend/src/__mocks__/notebook.ts
@@ -36,6 +36,7 @@ export const MockNotebook = {
hide_code: false,
disabled: false,
column: null,
+ expand_output: false,
...data.config,
},
edited: false,
diff --git a/frontend/src/components/editor/navigation/clipboard.ts b/frontend/src/components/editor/navigation/clipboard.ts
index f421c55c0e..5e890dcda4 100644
--- a/frontend/src/components/editor/navigation/clipboard.ts
+++ b/frontend/src/components/editor/navigation/clipboard.ts
@@ -35,6 +35,7 @@ const ClipboardCellDataSchema = z.object({
column: z.union([z.number(), z.null()]).optional(),
disabled: z.boolean().optional(),
hide_code: z.boolean().optional(),
+ expand_output: z.boolean().optional(),
})
.optional(),
}),
diff --git a/frontend/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap b/frontend/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap
index c3c1f6e946..6ea1cec1f7 100644
--- a/frontend/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap
+++ b/frontend/src/core/cells/__tests__/__snapshots__/cells.test.ts.snap
@@ -6,6 +6,7 @@ exports[`cell reducer > can initialize stdin > initial state 1`] = `
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [],
@@ -35,6 +36,7 @@ exports[`cell reducer > can initialize stdin > prepared for run 1`] = `
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [],
@@ -64,6 +66,7 @@ exports[`cell reducer > can initialize stdin > queued message received 1`] = `
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [],
@@ -93,6 +96,7 @@ exports[`cell reducer > can initialize stdin > running message received 1`] = `
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [],
@@ -122,6 +126,7 @@ exports[`cell reducer > can initialize stdin > second stdin requested 1`] = `
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [
@@ -171,6 +176,7 @@ exports[`cell reducer > can initialize stdin > stdin answered 1`] = `
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [
@@ -214,6 +220,7 @@ exports[`cell reducer > can initialize stdin > stdin requested 1`] = `
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [
@@ -256,6 +263,7 @@ exports[`cell reducer > can initialize stdin > stdout received 1`] = `
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [
@@ -292,6 +300,7 @@ exports[`cell reducer > can initialize stdin > stdout verified 1`] = `
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [
@@ -328,6 +337,7 @@ exports[`cell reducer > can receive console when the cell is idle and will clear
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [],
@@ -357,6 +367,7 @@ exports[`cell reducer > can receive console when the cell is idle and will clear
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [
@@ -393,6 +404,7 @@ exports[`cell reducer > can receive console when the cell is idle and will clear
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [],
@@ -422,6 +434,7 @@ exports[`cell reducer > can receive console when the cell is idle and will clear
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [
@@ -458,6 +471,7 @@ exports[`cell reducer > can receive console when the cell is idle and will clear
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [
@@ -494,6 +508,7 @@ exports[`cell reducer > can run a stale cell > queued message received 1`] = `
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [],
@@ -523,6 +538,7 @@ exports[`cell reducer > can run a stale cell > stale inputs received 1`] = `
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [],
@@ -552,6 +568,7 @@ exports[`cell reducer > can run a stopped cell > ancestor stopped 1`] = `
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [],
@@ -592,6 +609,7 @@ exports[`cell reducer > can run a stopped cell > idle message received 1`] = `
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [],
@@ -621,6 +639,7 @@ exports[`cell reducer > can run a stopped cell > queued after stop 1`] = `
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [],
@@ -661,6 +680,7 @@ exports[`cell reducer > can run a stopped cell > queued message received 1`] = `
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [],
@@ -690,6 +710,7 @@ exports[`cell reducer > can run a stopped cell > running after stop 1`] = `
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [],
@@ -720,6 +741,7 @@ import numpy",
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [
@@ -761,6 +783,7 @@ exports[`cell reducer > can run cell and receive cell messages > code edited 1`]
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [],
@@ -791,6 +814,7 @@ import numpy",
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [
@@ -832,6 +856,7 @@ exports[`cell reducer > can run cell and receive cell messages > code reverted 1
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [
@@ -873,6 +898,7 @@ exports[`cell reducer > can run cell and receive cell messages > console message
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [
@@ -910,6 +936,7 @@ import numpy",
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [
@@ -958,6 +985,7 @@ exports[`cell reducer > can run cell and receive cell messages > initial state 1
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [],
@@ -988,6 +1016,7 @@ import numpy",
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [
@@ -1034,6 +1063,7 @@ exports[`cell reducer > can run cell and receive cell messages > output received
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [
@@ -1075,6 +1105,7 @@ exports[`cell reducer > can run cell and receive cell messages > prepared for ru
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [],
@@ -1104,6 +1135,7 @@ exports[`cell reducer > can run cell and receive cell messages > queued message
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [],
@@ -1133,6 +1165,7 @@ exports[`cell reducer > can run cell and receive cell messages > running message
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [],
@@ -1162,6 +1195,7 @@ exports[`cell reducer > errors reset status to idle > code edited 1`] = `
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [],
@@ -1191,6 +1225,7 @@ exports[`cell reducer > errors reset status to idle > error response received 1`
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [],
@@ -1231,6 +1266,7 @@ exports[`cell reducer > errors reset status to idle > initial state 1`] = `
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [],
@@ -1260,6 +1296,7 @@ exports[`cell reducer > errors reset status to idle > prepared for run 1`] = `
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"consoleOutputs": [],
diff --git a/frontend/src/core/cells/__tests__/apply-transaction.test.ts b/frontend/src/core/cells/__tests__/apply-transaction.test.ts
index 7d5c12690e..c290bb5de1 100644
--- a/frontend/src/core/cells/__tests__/apply-transaction.test.ts
+++ b/frontend/src/core/cells/__tests__/apply-transaction.test.ts
@@ -380,6 +380,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 0,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
{
type: "set-config",
@@ -387,6 +388,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 1,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
]);
expect(prettyColumns(state)).toMatchInlineSnapshot(`
@@ -411,6 +413,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 0,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
{
type: "set-config",
@@ -418,6 +421,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 1,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
]);
expect(prettyColumns(state)).toMatchInlineSnapshot(`
@@ -439,6 +443,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 0,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
{
type: "set-config",
@@ -446,6 +451,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 1,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
{
type: "set-config",
@@ -453,6 +459,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 2,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
]);
expect(prettyColumns(state)).toMatchInlineSnapshot(`
@@ -475,6 +482,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 0,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
{
type: "set-config",
@@ -482,6 +490,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 1,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
{
type: "set-config",
@@ -489,6 +498,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 0,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
{
type: "set-config",
@@ -496,6 +506,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 1,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
]);
// a and c in col0; b and d in col1. Order within each column follows
@@ -518,6 +529,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 1,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
]);
// Without reorder-cells, the flat order comes from the current tree.
@@ -542,6 +554,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: null,
disabled: false,
hideCode: true,
+ expandOutput: false,
},
]);
// All three cells remain in a single column. No rebuild triggered.
@@ -571,6 +584,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 0,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
{
type: "set-config",
@@ -578,6 +592,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 1,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
]);
expect(prettyColumns(state)).toMatchInlineSnapshot(`
@@ -608,6 +623,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 0,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
{
type: "set-config",
@@ -615,6 +631,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 1,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
]);
expect(prettyColumns(state)).toMatchInlineSnapshot(`
@@ -632,6 +649,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 0,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
{
type: "set-config",
@@ -639,6 +657,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 0,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
]);
expect(prettyColumns(state)).toMatchInlineSnapshot(`
@@ -691,6 +710,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 0,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
{
type: "set-config",
@@ -698,6 +718,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 1,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
]);
expect(prettyColumns(state)).toMatchInlineSnapshot(`
@@ -752,6 +773,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 0,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
{
type: "set-config",
@@ -759,6 +781,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 1,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
]);
expect(prettyColumns(state)).toMatchInlineSnapshot(`
@@ -776,6 +799,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 0,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
]);
expect(prettyColumns(state)).toMatchInlineSnapshot(`
@@ -798,6 +822,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 0,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
{
type: "set-config",
@@ -805,6 +830,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 1,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
{
type: "set-config",
@@ -812,6 +838,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 1,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
]);
expect(prettyColumns(state)).toMatchInlineSnapshot(`
@@ -830,6 +857,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 0,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
]);
expect(prettyColumns(state)).toMatchInlineSnapshot(`
@@ -855,6 +883,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 0,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
{
type: "set-config",
@@ -862,6 +891,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 1,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
// reorder-cells comes afterwards.
{ type: "reorder-cells", cellIds: [a, b, c, d] },
@@ -889,6 +919,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 0,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
{ type: "set-code", cellId: a, code: "x = 1" },
{
@@ -897,6 +928,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 1,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
{ type: "reorder-cells", cellIds: [a, b, c, d] },
{ type: "set-name", cellId: d, name: "last" },
@@ -929,6 +961,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 0,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
{
type: "set-config",
@@ -936,6 +969,7 @@ describe("applyTransactionChanges column rebuild", () => {
column: 1,
disabled: false,
hideCode: false,
+ expandOutput: false,
},
]);
expect(prettyColumns(state)).toMatchInlineSnapshot(`
diff --git a/frontend/src/core/cells/__tests__/cells.test.ts b/frontend/src/core/cells/__tests__/cells.test.ts
index 43eaa6f4ae..40f6c2d797 100644
--- a/frontend/src/core/cells/__tests__/cells.test.ts
+++ b/frontend/src/core/cells/__tests__/cells.test.ts
@@ -1233,6 +1233,7 @@ describe("cell reducer", () => {
disabled: false,
hide_code: false,
column: null,
+ expand_output: false,
});
actions.updateCellConfig({
diff --git a/frontend/src/core/cells/__tests__/document-changes.test.ts b/frontend/src/core/cells/__tests__/document-changes.test.ts
index bb12a37e02..3af4230667 100644
--- a/frontend/src/core/cells/__tests__/document-changes.test.ts
+++ b/frontend/src/core/cells/__tests__/document-changes.test.ts
@@ -153,6 +153,7 @@ describe("toDocumentChanges", () => {
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"name": "_",
@@ -183,6 +184,7 @@ describe("toDocumentChanges", () => {
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"name": "_",
@@ -229,6 +231,7 @@ describe("toDocumentChanges", () => {
"cellId": "0",
"column": null,
"disabled": false,
+ "expandOutput": false,
"hideCode": true,
"type": "set-config",
},
@@ -236,6 +239,29 @@ describe("toDocumentChanges", () => {
`);
});
+ it("maps expand_output to expandOutput in set-config", () => {
+ setup("a");
+ const [a] = state.cellIds.inOrderIds;
+
+ const { changes } = resolve(state, {
+ type: "updateCellConfig",
+ payload: { cellId: a, config: { expand_output: true } },
+ });
+
+ expect(changes).toMatchInlineSnapshot(`
+ [
+ {
+ "cellId": "0",
+ "column": null,
+ "disabled": false,
+ "expandOutput": true,
+ "hideCode": false,
+ "type": "set-config",
+ },
+ ]
+ `);
+ });
+
it("includes full CellConfig in create-cell", () => {
setup("a");
@@ -246,13 +272,14 @@ describe("toDocumentChanges", () => {
before: false,
code: "hidden",
newCellId: CellId.create(),
+ config: { expand_output: true },
hideCode: true,
},
});
expect(changes[0]).toMatchObject({
type: "create-cell",
- config: { hide_code: true },
+ config: { hide_code: true, expand_output: true },
});
});
});
@@ -273,6 +300,7 @@ describe("toDocumentChanges", () => {
"cellId": "1",
"column": 1,
"disabled": false,
+ "expandOutput": false,
"hideCode": false,
"type": "set-config",
},
@@ -302,6 +330,7 @@ describe("toDocumentChanges", () => {
"cellId": "1",
"column": 1,
"disabled": false,
+ "expandOutput": false,
"hideCode": false,
"type": "set-config",
},
@@ -309,6 +338,7 @@ describe("toDocumentChanges", () => {
"cellId": "2",
"column": 1,
"disabled": false,
+ "expandOutput": false,
"hideCode": false,
"type": "set-config",
},
@@ -343,6 +373,7 @@ describe("toDocumentChanges", () => {
"cellId": "1",
"column": 0,
"disabled": false,
+ "expandOutput": false,
"hideCode": false,
"type": "set-config",
},
@@ -350,6 +381,7 @@ describe("toDocumentChanges", () => {
"cellId": "2",
"column": 0,
"disabled": false,
+ "expandOutput": false,
"hideCode": false,
"type": "set-config",
},
@@ -386,6 +418,7 @@ describe("toDocumentChanges", () => {
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"name": "_",
@@ -395,6 +428,7 @@ describe("toDocumentChanges", () => {
"cellId": "1",
"column": 1,
"disabled": false,
+ "expandOutput": false,
"hideCode": false,
"type": "set-config",
},
@@ -458,6 +492,7 @@ describe("toDocumentChanges", () => {
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"name": "_",
@@ -521,6 +556,7 @@ describe("toDocumentChanges", () => {
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"name": "_",
@@ -559,6 +595,7 @@ describe("toDocumentChanges", () => {
"config": {
"column": null,
"disabled": false,
+ "expand_output": false,
"hide_code": false,
},
"name": "setup",
@@ -648,6 +685,7 @@ describe("coalesceChanges", () => {
column: null,
disabled: true,
hideCode: false,
+ expandOutput: false,
},
{ type: "move-cell", cellId: X, after: A },
{ type: "delete-cell", cellId: X },
diff --git a/frontend/src/core/cells/__tests__/outputs.test.tsx b/frontend/src/core/cells/__tests__/outputs.test.tsx
new file mode 100644
index 0000000000..8475b8825f
--- /dev/null
+++ b/frontend/src/core/cells/__tests__/outputs.test.tsx
@@ -0,0 +1,117 @@
+/* Copyright 2026 Marimo. All rights reserved. */
+
+import { act, renderHook } from "@testing-library/react";
+import { createStore, Provider } from "jotai";
+import { beforeEach, describe, expect, it, vi } from "vitest";
+import { MockNotebook } from "@/__mocks__/notebook";
+import { notebookAtom } from "@/core/cells/cells";
+import { CellId } from "@/core/cells/ids";
+import { type AppMode, viewStateAtom } from "@/core/mode";
+import { useExpandedConsoleOutput, useExpandedOutput } from "../outputs";
+
+const saveCellConfig = vi.fn().mockResolvedValue(null);
+
+vi.mock("@/core/network/requests", () => ({
+ getRequestClient: () => ({ saveCellConfig }),
+}));
+
+function setup(opts: { mode: AppMode; expandOutput?: boolean }) {
+ const cellId = CellId.create();
+ const store = createStore();
+ store.set(
+ notebookAtom,
+ MockNotebook.notebookState({
+ cellData: {
+ [cellId]: { config: { expand_output: opts.expandOutput ?? false } },
+ },
+ }),
+ );
+ store.set(viewStateAtom, { mode: opts.mode, cellAnchor: null });
+
+ const { result } = renderHook(() => useExpandedOutput(cellId), {
+ wrapper: ({ children }) => <Provider store={store}>{children}</Provider>,
+ });
+
+ return { cellId, store, result };
+}
+
+const configOf = (store: ReturnType<typeof createStore>, cellId: CellId) =>
+ store.get(notebookAtom).cellData[cellId].config;
+
+describe("useExpandedOutput", () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ });
+
+ it("reads the initial state from the cell's expand_output config", () => {
+ expect(setup({ mode: "edit" }).result.current[0]).toBe(false);
+ expect(setup({ mode: "edit", expandOutput: true }).result.current[0]).toBe(
+ true,
+ );
+ });
+
+ it("persists the toggle to the cell's config in edit mode", () => {
+ const { cellId, store, result } = setup({ mode: "edit" });
+
+ act(() => result.current[1](true));
+
+ expect(result.current[0]).toBe(true);
+ expect(configOf(store, cellId).expand_output).toBe(true);
+ expect(saveCellConfig).toHaveBeenCalledWith({
+ configs: { [cellId]: { expand_output: true } },
+ });
+ });
+
+ it("collapses by clearing the config", () => {
+ const { cellId, store, result } = setup({
+ mode: "edit",
+ expandOutput: true,
+ });
+
+ act(() => result.current[1](false));
+
+ expect(result.current[0]).toBe(false);
+ expect(configOf(store, cellId).expand_output).toBe(false);
+ expect(saveCellConfig).toHaveBeenCalledWith({
+ configs: { [cellId]: { expand_output: false } },
+ });
+ });
+
+ it("keeps the toggle in memory outside of edit mode", () => {
+ const { cellId, store, result } = setup({ mode: "read" });
+
+ act(() => result.current[1](true));
+
+ expect(result.current[0]).toBe(true);
+ // Cell configs are read-only outside of edit mode.
+ expect(configOf(store, cellId).expand_output).toBe(false);
+ expect(saveCellConfig).not.toHaveBeenCalled();
+ });
+
+ it("still honors expand_output outside of edit mode", () => {
+ const { result } = setup({ mode: "read", expandOutput: true });
+ expect(result.current[0]).toBe(true);
+ });
+
+ // `expand_output` covers the cell's output area only. Console output is
+ // clamped independently and stays an in-memory, per-session toggle.
+ it("does not touch the config when console output is expanded", () => {
+ const cellId = CellId.create();
+ const store = createStore();
+ store.set(
+ notebookAtom,
+ MockNotebook.notebookState({ cellData: { [cellId]: {} } }),
+ );
+ store.set(viewStateAtom, { mode: "edit", cellAnchor: null });
+
+ const { result } = renderHook(() => useExpandedConsoleOutput(cellId), {
+ wrapper: ({ children }) => <Provider store={store}>{children}</Provider>,
+ });
+
+ act(() => result.current[1](true));
+
+ expect(result.current[0]).toBe(true);
+ expect(configOf(store, cellId).expand_output).toBe(false);
+ expect(saveCellConfig).not.toHaveBeenCalled();
+ });
+});
diff --git a/frontend/src/core/cells/__tests__/session.test.ts b/frontend/src/core/cells/__tests__/session.test.ts
index b60ce173f1..6c8afdc65e 100644
--- a/frontend/src/core/cells/__tests__/session.test.ts
+++ b/frontend/src/core/cells/__tests__/session.test.ts
@@ -59,6 +59,7 @@ describe("notebookStateFromSession", () => {
column: config?.column ?? null,
disabled: config?.disabled ?? null,
hide_code: config?.hide_code ?? null,
+ expand_output: config?.expand_output ?? null,
},
});
@@ -298,6 +299,7 @@ describe("notebookStateFromSession", () => {
hide_code: false,
disabled: false,
column: null,
+ expand_output: false,
},
serializedEditorState: null,
});
@@ -309,6 +311,7 @@ describe("notebookStateFromSession", () => {
hide_code: true,
disabled: true,
column: 1,
+ expand_output: true,
}),
]);
const result = notebookStateFromSession(null, notebook);
@@ -319,6 +322,7 @@ describe("notebookStateFromSession", () => {
hide_code: true,
disabled: true,
column: 1,
+ expand_output: true,
});
});
@@ -350,6 +354,7 @@ describe("notebookStateFromSession", () => {
hide_code: false,
disabled: false,
column: null,
+ expand_output: false,
},
serializedEditorState: null,
});
@@ -386,6 +391,7 @@ describe("notebookStateFromSession", () => {
hide_code: false,
disabled: false,
column: null,
+ expand_output: false,
},
serializedEditorState: null,
});
@@ -426,6 +432,7 @@ describe("notebookStateFromSession", () => {
hide_code: false,
disabled: false,
column: null,
+ expand_output: false,
},
serializedEditorState: null,
});
diff --git a/frontend/src/core/cells/cells.ts b/frontend/src/core/cells/cells.ts
index f4128bb7ec..8f0bc96d21 100644
--- a/frontend/src/core/cells/cells.ts
+++ b/frontend/src/core/cells/cells.ts
@@ -125,7 +125,12 @@ export interface NotebookState {
}
function withScratchCell(notebookState: NotebookState): NotebookState {
- const config = { column: 0, hide_code: false, disabled: false };
+ const config = {
+ column: 0,
+ hide_code: false,
+ disabled: false,
+ expand_output: false,
+ };
return {
...notebookState,
cellData: {
diff --git a/frontend/src/core/cells/document-changes.ts b/frontend/src/core/cells/document-changes.ts
index 35386471d6..924b6bbcca 100644
--- a/frontend/src/core/cells/document-changes.ts
+++ b/frontend/src/core/cells/document-changes.ts
@@ -164,6 +164,7 @@ function columnChanges(
column: newCol,
disabled: cell?.config.disabled ?? false,
hideCode: cell?.config.hide_code ?? false,
+ expandOutput: cell?.config.expand_output ?? false,
});
}
}
@@ -277,6 +278,7 @@ export function toDocumentChanges(
column: cell.config.column ?? null,
disabled: cell.config.disabled ?? false,
hideCode: cell.config.hide_code ?? false,
+ expandOutput: cell.config.expand_output ?? false,
},
];
}
@@ -452,7 +454,11 @@ export function fromDocumentChanges(
payload: { cellId: change.cellId, name: change.name },
});
}
- if (change.config?.disabled != null || change.config?.column != null) {
+ if (
+ change.config?.disabled != null ||
+ change.config?.column != null ||
+ change.config?.expand_output != null
+ ) {
actions.push({
type: "updateCellConfig",
payload: {
@@ -464,6 +470,9 @@ export function fromDocumentChanges(
...(change.config.column != null && {
column: change.config.column,
}),
+ ...(change.config.expand_output != null && {
+ expand_output: change.config.expand_output,
+ }),
},
},
});
@@ -560,6 +569,7 @@ export function fromDocumentChanges(
column: change.column,
disabled: change.disabled,
hide_code: change.hideCode,
+ expand_output: change.expandOutput,
},
},
});
diff --git a/frontend/src/core/cells/outputs.ts b/frontend/src/core/cells/outputs.ts
index 52206a9e1d..a700144b17 100644
--- a/frontend/src/core/cells/outputs.ts
+++ b/frontend/src/core/cells/outputs.ts
@@ -1,34 +1,91 @@
/* Copyright 2026 Marimo. All rights reserved. */
-import { useEffect, useState } from "react";
+import { useAtomValue } from "jotai";
+import { selectAtom } from "jotai/utils";
+import { useEffect, useMemo, useState } from "react";
+import { useEvent } from "@/hooks/useEvent";
+import { Logger } from "@/utils/Logger";
import type { OutputMessage } from "../kernel/messages";
+import { viewStateAtom } from "../mode";
+import { getRequestClient } from "../network/requests";
+import { cellDataAtom, useCellActions } from "./cells";
import type { CellId } from "./ids";
// This does not need to be overcomplicated. We can just store the expanded
// state in a global map instead of Jotai since state is not shared between cells.
+// The output area only falls back to its map where the `expand_output` config
+// cannot be edited; see `useExpandedOutput`.
const expandedOutputs: Record<CellId, boolean> = {};
const expandedConsoleOutputs: Record<CellId, boolean> = {};
+/**
+ * Whether a cell's output is shown in full, instead of clamped to a fixed
+ * height. Covers the cell's output area only; console output is clamped
+ * independently, via `useExpandedConsoleOutput`.
+ *
+ * In edit mode, we toggle the cell's `expand_output` config, so the choice is persisted.
+ */
export function useExpandedOutput(cellId: CellId) {
- const [state, setState] = useState(expandedOutputs[cellId] ?? false);
+ const { mode } = useAtomValue(viewStateAtom);
+ const { updateCellConfig } = useCellActions();
+ // Select just the flag: every output would otherwise re-render on each
+ // keystroke in its cell.
+ const isConfigExpanded = useAtomValue(
+ useMemo(
+ () =>
+ selectAtom(
+ cellDataAtom(cellId),
+ (data) => data?.config.expand_output ?? false,
+ Object.is,
+ ),
+ [cellId],
+ ),
+ );
+ const [isSessionExpanded, setIsSessionExpanded] = useState(
+ () => expandedOutputs[cellId] ?? isConfigExpanded,
+ );
// Sync state to external storage
useEffect(() => {
- expandedOutputs[cellId] = state;
- }, [cellId, state]);
+ expandedOutputs[cellId] = isSessionExpanded;
+ }, [cellId, isSessionExpanded]);
- return [state, setState] as const;
+ const isEditable = mode === "edit";
+ const isExpanded = isEditable ? isConfigExpanded : isSessionExpanded;
+
+ const setIsExpanded = useEvent((expanded: boolean) => {
+ setIsSessionExpanded(expanded);
+ if (!isEditable) {
+ return;
+ }
+ const config = { expand_output: expanded };
+ updateCellConfig({ cellId, config });
+ getRequestClient()
+ .saveCellConfig({ configs: { [cellId]: config } })
+ .catch((error) => {
+ Logger.error("Failed to save expand_output config", error);
+ });
+ });
+
+ return [isExpanded, setIsExpanded] as const;
}
+/**
+ * Whether a cell's console output is shown in full. Deliberately not backed by
+ * `expand_output`: that config covers the cell's output area only, so console
+ * output stays a per-session, in-memory toggle.
+ */
export function useExpandedConsoleOutput(cellId: CellId) {
- const [state, setState] = useState(expandedConsoleOutputs[cellId] ?? false);
+ const [isExpanded, setIsExpanded] = useState(
+ expandedConsoleOutputs[cellId] ?? false,
+ );
// Sync state to external storage
useEffect(() => {
- expandedConsoleOutputs[cellId] = state;
- }, [cellId, state]);
+ expandedConsoleOutputs[cellId] = isExpanded;
+ }, [cellId, isExpanded]);
- return [state, setState] as const;
+ return [isExpanded, setIsExpanded] as const;
}
export function isOutputEmpty(
diff --git a/frontend/src/core/cells/session.ts b/frontend/src/core/cells/session.ts
index 7150d25b11..13a7aec355 100644
--- a/frontend/src/core/cells/session.ts
+++ b/frontend/src/core/cells/session.ts
@@ -149,6 +149,7 @@ function createEmptyNotebookCell(): NotebookCell {
column: null,
disabled: false,
hide_code: false,
+ expand_output: false,
},
};
}
@@ -177,6 +178,7 @@ function createCellDataFromNotebook(
column: notebookCell.config?.column ?? null,
disabled: notebookCell.config?.disabled ?? false,
hide_code: notebookCell.config?.hide_code ?? false,
+ expand_output: notebookCell.config?.expand_output ?? false,
},
serializedEditorState: null,
};
diff --git a/frontend/src/core/cells/types.ts b/frontend/src/core/cells/types.ts
index 4a26d2f0dd..bb7420d4c7 100644
--- a/frontend/src/core/cells/types.ts
+++ b/frontend/src/core/cells/types.ts
@@ -27,6 +27,7 @@ export function createCell({
hide_code: false,
disabled: false,
column: null,
+ expand_output: false,
},
name: name,
code: code,
@@ -42,6 +43,7 @@ export function createCellConfig(config?: Partial<CellConfig>): CellConfig {
hide_code: false,
disabled: false,
column: null,
+ expand_output: false,
...config,
};
}
diff --git a/marimo/_ast/app.py b/marimo/_ast/app.py
index 3cd20f9a59..4a5d7f9cf1 100644
--- a/marimo/_ast/app.py
+++ b/marimo/_ast/app.py
@@ -187,6 +187,7 @@ class _SetupContext:
column=existing_cfg.column,
disabled=existing_cfg.disabled,
hide_code=hide_code,
+ expand_output=existing_cfg.expand_output,
),
),
source="cell-manager",
@@ -365,6 +366,7 @@ class App:
column: int | None = None,
disabled: bool = False,
hide_code: bool = False,
+ expand_output: bool = False,
**kwargs: Any,
) -> Cell | Callable[[Fn[P, R]], Cell]:
"""A decorator to add a cell to the app.
@@ -391,6 +393,9 @@ class App:
column: The column number to place this cell in.
disabled: Whether to disable the cell.
hide_code: Whether to hide the cell's code.
+ expand_output: Whether to show the cell's output in full; when
+ False, a tall output is clamped to a fixed height in the
+ editor. Does not affect console output.
**kwargs: For forward-compatibility with future arguments.
"""
del kwargs
@@ -398,7 +403,12 @@ class App:
return cast(
Cell | Callable[[Fn[P, R]], Cell],
self._cell_manager.cell_decorator(
- func, column, disabled, hide_code, app=InternalApp(self)
+ func,
+ column,
+ disabled,
+ hide_code,
+ expand_output=expand_output,
+ app=InternalApp(self),
),
)
@@ -425,6 +435,7 @@ class App:
column: int | None = None,
disabled: bool = False,
hide_code: bool = False,
+ expand_output: bool = False,
**kwargs: Any,
) -> Fn[P, R] | Callable[[Fn[P, R]], Fn[P, R]]:
"""A decorator to wrap a callable function into a marimo cell.
@@ -453,6 +464,9 @@ class App:
column: The column number to place this cell in.
disabled: Whether to disable the cell.
hide_code: Whether to hide the cell's code.
+ expand_output: Whether to show the cell's output in full; when
+ False, a tall output is clamped to a fixed height in the
+ editor. Does not affect console output.
**kwargs: For forward-compatibility with future arguments.
"""
del kwargs
@@ -464,6 +478,7 @@ class App:
column,
disabled,
hide_code,
+ expand_output=expand_output,
app=InternalApp(self),
top_level=True,
),
@@ -482,6 +497,7 @@ class App:
column: int | None = None,
disabled: bool = False,
hide_code: bool = False,
+ expand_output: bool = False,
**kwargs: Any,
) -> Cls | Callable[[Cls], Cls]:
"""A decorator to wrap a class into a marimo cell.
@@ -508,6 +524,9 @@ class App:
column: The column number to place this cell in.
disabled: Whether to disable the cell.
hide_code: Whether to hide the cell's code.
+ expand_output: Whether to show the cell's output in full; when
+ False, a tall output is clamped to a fixed height in the
+ editor. Does not affect console output.
**kwargs: For forward-compatibility with future arguments.
"""
del kwargs
@@ -519,6 +538,7 @@ class App:
column,
disabled,
hide_code,
+ expand_output=expand_output,
app=InternalApp(self),
top_level=True,
),
diff --git a/marimo/_ast/cell.py b/marimo/_ast/cell.py
index d7888ffc7e..2e486df6ec 100644
--- a/marimo/_ast/cell.py
+++ b/marimo/_ast/cell.py
@@ -47,6 +47,11 @@ class CellConfig(msgspec.Struct):
# If True, the cell is hidden from the editor.
hide_code: bool = False
+ # If True, the cell's output is shown in full in the editor; otherwise the
+ # output is clamped to a fixed height, with an option to expand it. Does
+ # not apply to console output, which is clamped independently.
+ expand_output: bool = False
+
@classmethod
def from_dict(
cls, kwargs: dict[str, Any], warn: bool = True
@@ -87,6 +92,16 @@ CellConfigKeys = frozenset(
{field.name for field in msgspec.structs.fields(CellConfig)}
)
+# Config keys whose values are plain booleans; useful for formats that
+# serialize cell config as strings (e.g. markdown tag attributes).
+CellConfigBooleanKeys = frozenset(
+ {
+ field.name
+ for field in msgspec.structs.fields(CellConfig)
+ if field.type is bool
+ }
+)
+
# States in a cell's runtime state machine
#
diff --git a/marimo/_ast/cell_manager.py b/marimo/_ast/cell_manager.py
index 06b7e508ea..299a7b41d0 100644
--- a/marimo/_ast/cell_manager.py
+++ b/marimo/_ast/cell_manager.py
@@ -105,6 +105,7 @@ class CellManager:
hide_code: bool,
app: InternalApp | None = None,
*,
+ expand_output: bool = False,
top_level: bool = False,
) -> Cell | Obj[P, R] | Callable[[Obj[P, R]], Cell | Obj[P, R]]:
"""Create a cell decorator for marimo notebook cells."""
@@ -112,7 +113,10 @@ class CellManager:
# path. This code is only called when run as a script or imported as a
# module.
cell_config = CellConfig(
- column=column, disabled=disabled, hide_code=hide_code
+ column=column,
+ disabled=disabled,
+ hide_code=hide_code,
+ expand_output=expand_output,
)
def _register(obj: Obj[P, R]) -> Cell | Obj[P, R]:
@@ -607,6 +611,7 @@ class CellManager:
column=cd.config.column,
disabled=cd.config.disabled,
hide_code=cd.config.hide_code,
+ expand_output=cd.config.expand_output,
)
)
changed_cell_ids.add(cd.cell_id)
diff --git a/marimo/_code_mode/_context.py b/marimo/_code_mode/_context.py
index 3689185f35..14ac4fc9f6 100644
--- a/marimo/_code_mode/_context.py
+++ b/marimo/_code_mode/_context.py
@@ -1241,6 +1241,7 @@ class AsyncCodeModeContext:
if disabled is not None
else existing.disabled,
column=column if column is not None else existing.column,
+ expand_output=existing.expand_output,
)
self._ops.append(
@@ -1934,6 +1935,7 @@ def _plan_to_document_ops(
column=resolved_cfg.column,
disabled=resolved_cfg.disabled,
hide_code=resolved_cfg.hide_code,
+ expand_output=resolved_cfg.expand_output,
)
)
diff --git a/marimo/_convert/ipynb/to_ir.py b/marimo/_convert/ipynb/to_ir.py
index 1b31401bfe..11ba7b1ea8 100644
--- a/marimo/_convert/ipynb/to_ir.py
+++ b/marimo/_convert/ipynb/to_ir.py
@@ -1307,10 +1307,11 @@ def bind_cell_metadata(
CodeCell(
source=source,
name=name,
- config=CellConfig(
- hide_code=hide_code,
- column=marimo_config.get("column"),
- disabled=marimo_config.get("disabled", False),
+ # Restore every config key the exporter wrote (column,
+ # disabled, expand_output, ...); hide_code is resolved above
+ # since tags and Jupyter hints can also set it.
+ config=CellConfig.from_dict(
+ {**marimo_config, "hide_code": hide_code}
),
)
)
diff --git a/marimo/_convert/markdown/to_ir.py b/marimo/_convert/markdown/to_ir.py
index 10a8f15aa1..48ac9cda9f 100644
--- a/marimo/_convert/markdown/to_ir.py
+++ b/marimo/_convert/markdown/to_ir.py
@@ -31,7 +31,7 @@ from pymdownx.superfences import ( # type: ignore
)
from marimo import _loggers
-from marimo._ast.cell import CellConfig
+from marimo._ast.cell import CellConfig, CellConfigBooleanKeys
from marimo._ast.names import DEFAULT_CELL_NAME
from marimo._convert.common.format import markdown_to_marimo, sql_to_marimo
from marimo._convert.markdown.flavor import (
@@ -169,13 +169,13 @@ def get_source_from_tag(tag: Element) -> str:
def get_cell_config_from_tag(tag: Element, **defaults: bool) -> CellConfig:
- # Known boolean attributes.
+ # Boolean attributes are serialized as "true"/"false".
extracted_attrs: dict[str, bool | int] = {
**defaults,
**{
k: v == "true"
for k, v in tag.attrib.items()
- if k in ["hide_code", "disabled"]
+ if k in CellConfigBooleanKeys
},
}
# "Column" is not a boolean attribute.
diff --git a/marimo/_messaging/notebook/changes.py b/marimo/_messaging/notebook/changes.py
index 9c88a8d634..c602756393 100644
--- a/marimo/_messaging/notebook/changes.py
+++ b/marimo/_messaging/notebook/changes.py
@@ -82,6 +82,7 @@ class SetConfig(msgspec.Struct, frozen=True, tag="set-config", rename="camel"):
column: int | None
disabled: bool
hide_code: bool
+ expand_output: bool
DocumentChange = (
diff --git a/marimo/_messaging/notebook/document.py b/marimo/_messaging/notebook/document.py
index 1e5558f036..05bfd6c40e 100644
--- a/marimo/_messaging/notebook/document.py
+++ b/marimo/_messaging/notebook/document.py
@@ -246,6 +246,7 @@ class NotebookDocument:
column=change.column,
disabled=change.disabled,
hide_code=change.hide_code,
+ expand_output=change.expand_output,
)
else:
assert_never(change)
diff --git a/marimo/_schemas/generated/notebook.yaml b/marimo/_schemas/generated/notebook.yaml
index 33b31dc4bd..b92db918df 100644
--- a/marimo/_schemas/generated/notebook.yaml
+++ b/marimo/_schemas/generated/notebook.yaml
@@ -41,6 +41,10 @@ components:
anyOf:
- type: boolean
- type: 'null'
+ expand_output:
+ anyOf:
+ - type: boolean
+ - type: 'null'
hide_code:
anyOf:
- type: boolean
diff --git a/marimo/_schemas/generated/notifications.yaml b/marimo/_schemas/generated/notifications.yaml
index 0eeee88b86..742884a6b7 100644
--- a/marimo/_schemas/generated/notifications.yaml
+++ b/marimo/_schemas/generated/notifications.yaml
@@ -122,6 +122,9 @@ components:
disabled:
default: false
type: boolean
+ expand_output:
+ default: false
+ type: boolean
hide_code:
default: false
type: boolean
diff --git a/marimo/_schemas/notebook.py b/marimo/_schemas/notebook.py
index 8dd4473d4c..e406d80c35 100644
--- a/marimo/_schemas/notebook.py
+++ b/marimo/_schemas/notebook.py
@@ -17,6 +17,7 @@ class NotebookCellConfig(TypedDict, total=False):
column: int | None
disabled: bool | None
hide_code: bool | None
+ expand_output: bool | None
class NotebookCell(TypedDict):
diff --git a/marimo/_session/state/serialize.py b/marimo/_session/state/serialize.py
index 3e962f822f..8e118713e9 100644
--- a/marimo/_session/state/serialize.py
+++ b/marimo/_session/state/serialize.py
@@ -373,6 +373,7 @@ def serialize_notebook(
column=None,
disabled=None,
hide_code=None,
+ expand_output=None,
)
else:
name = cell_data.name
@@ -380,6 +381,7 @@ def serialize_notebook(
column=cell_data.config.column,
disabled=cell_data.config.disabled,
hide_code=cell_data.config.hide_code,
+ expand_output=cell_data.config.expand_output,
)
cells.append(
diff --git a/packages/openapi/api.yaml b/packages/openapi/api.yaml
index 56f6da6474..68d555e3b6 100644
--- a/packages/openapi/api.yaml
+++ b/packages/openapi/api.yaml
@@ -438,6 +438,9 @@ components:
disabled:
default: false
type: boolean
+ expand_output:
+ default: false
+ type: boolean
hide_code:
default: false
type: boolean
@@ -5297,6 +5300,8 @@ components:
- type: 'null'
disabled:
type: boolean
+ expandOutput:
+ type: boolean
hideCode:
type: boolean
type:
@@ -5308,6 +5313,7 @@ components:
- column
- disabled
- hideCode
+ - expandOutput
title: SetConfig
type: object
SetName:
diff --git a/packages/openapi/src/api.ts b/packages/openapi/src/api.ts
index 9ba4cdd7d2..3bc0351bcf 100644
--- a/packages/openapi/src/api.ts
+++ b/packages/openapi/src/api.ts
@@ -4115,6 +4115,8 @@ export interface components {
/** @default false */
disabled?: boolean;
/** @default false */
+ expand_output?: boolean;
+ /** @default false */
hide_code?: boolean;
};
/** Format: cell-id */
@@ -7060,6 +7062,7 @@ export interface components {
cellId: components["schemas"]["CellId"];
column: number | null;
disabled: boolean;
+ expandOutput: boolean;
hideCode: boolean;
/** @enum {unknown} */
type: "set-config";
diff --git a/packages/openapi/src/notebook.ts b/packages/openapi/src/notebook.ts
index 92340d223b..0fd8e358dd 100644
--- a/packages/openapi/src/notebook.ts
+++ b/packages/openapi/src/notebook.ts
@@ -25,6 +25,7 @@ export interface components {
NotebookCellConfig: {
column?: number | null;
disabled?: boolean | null;
+ expand_output?: boolean | null;
hide_code?: boolean | null;
};
/**
diff --git a/tests/_ast/test_app.py b/tests/_ast/test_app.py
index e0b11dc7a3..a44b87a356 100644
--- a/tests/_ast/test_app.py
+++ b/tests/_ast/test_app.py
@@ -543,11 +543,35 @@ class TestApp:
assert __x__ == 0
return
+ @app.cell(expand_output=True)
+ def _() -> None:
+ return
+
cell_manager = app._cell_manager
configs = tuple(cell_manager.configs())
assert configs[0].disabled
assert configs[0].column is not None
assert configs[1].hide_code
+ assert not configs[1].expand_output
+ assert configs[2].expand_output
+
+ @staticmethod
+ def test_top_level_cell_config() -> None:
+ # Codegen emits `expand_output` for top-level cells too, so the
+ # decorators must accept it -- otherwise the flag is dropped when the
+ # notebook is imported or run as a script.
+ app = App()
+
+ @app.function(expand_output=True)
+ def add(a: int, b: int) -> int:
+ return a + b
+
+ @app.class_definition(expand_output=True)
+ class Struct: ...
+
+ configs = tuple(app._cell_manager.configs())
+ assert configs[0].expand_output
+ assert configs[1].expand_output
@staticmethod
def test_conditional_definition() -> None:
diff --git a/tests/_ast/test_codegen.py b/tests/_ast/test_codegen.py
index 5766cef26b..167cc578f4 100644
--- a/tests/_ast/test_codegen.py
+++ b/tests/_ast/test_codegen.py
@@ -327,14 +327,16 @@ app._unparsable_cell(
assert generate(
"x = 1",
"named_cell",
- CellConfig(disabled=True, hide_code=True, column=1),
+ CellConfig(
+ disabled=True, hide_code=True, column=1, expand_output=True
+ ),
) == snapshot(
'''\
app._unparsable_cell(
r"""
x = 1
""",
- column=1, disabled=True, hide_code=True, name="named_cell"
+ column=1, disabled=True, hide_code=True, expand_output=True, name="named_cell"
)\
'''
)
@@ -948,11 +950,13 @@ class TestToFunctionDef:
def test_with_all_config(self) -> None:
code = "x = 0"
cell = compile_cell(code)
- cell = cell.configure(CellConfig(disabled=True, hide_code=True))
+ cell = cell.configure(
+ CellConfig(disabled=True, hide_code=True, expand_output=True)
+ )
fndef = codegen.to_functiondef(cell, "foo")
expected = "\n".join(
[
- "@app.cell(disabled=True, hide_code=True)",
+ "@app.cell(disabled=True, hide_code=True, expand_output=True)",
"def foo():",
" x = 0",
" return (x,)",
@@ -960,6 +964,27 @@ class TestToFunctionDef:
)
assert fndef == expected
+ def test_with_expand_output(self) -> None:
+ code = "x = 0"
+ cell = compile_cell(code)
+ cell = cell.configure(CellConfig(expand_output=True))
+ fndef = codegen.to_functiondef(cell, "foo")
+ expected = "\n".join(
+ [
+ "@app.cell(expand_output=True)",
+ "def foo():",
+ " x = 0",
+ " return (x,)",
+ ]
+ )
+ assert fndef == expected
+
+ def test_expand_output_omitted_when_false(self) -> None:
+ code = "x = 0"
+ cell = compile_cell(code)
+ cell = cell.configure(CellConfig(expand_output=False))
+ assert codegen.to_functiondef(cell, "foo").startswith("@app.cell\n")
+
def test_dotted_names_filtered_from_signature(self) -> None:
"""Test that dotted names (like SQL schema.table references) are filtered out from function signatures."""
# Create a cell with a dotted reference in refs (simulating SQL schema.table)
diff --git a/tests/_code_mode/test_code_mode_context.py b/tests/_code_mode/test_code_mode_context.py
index 6d4bf973d9..29ca5f9593 100644
--- a/tests/_code_mode/test_code_mode_context.py
+++ b/tests/_code_mode/test_code_mode_context.py
@@ -97,6 +97,7 @@ class TestAddCell:
"column": None,
"disabled": False,
"hide_code": True,
+ "expand_output": False,
},
"before": None,
"after": None,
@@ -323,6 +324,7 @@ class TestUpdateCell:
"column": None,
"disabled": False,
"hideCode": True,
+ "expandOutput": False,
},
{"type": "reorder-cells", "cellIds": ("0",)},
]
diff --git a/tests/_convert/ipynb/fixtures/py/cell_config.py b/tests/_convert/ipynb/fixtures/py/cell_config.py
index 6caf43efb0..e469661a61 100644
--- a/tests/_convert/ipynb/fixtures/py/cell_config.py
+++ b/tests/_convert/ipynb/fixtures/py/cell_config.py
@@ -37,5 +37,11 @@ def _(y):
return
[email protected](expand_output=True)
+def _(y):
+ z = y + 1
+ return
+
+
if __name__ == "__main__":
app.run()
diff --git a/tests/_convert/ipynb/snapshots/cell_config_top_down.ipynb.txt b/tests/_convert/ipynb/snapshots/cell_config_top_down.ipynb.txt
index ef87201555..95df0775bf 100644
--- a/tests/_convert/ipynb/snapshots/cell_config_top_down.ipynb.txt
+++ b/tests/_convert/ipynb/snapshots/cell_config_top_down.ipynb.txt
@@ -60,6 +60,22 @@
"source": [
"print(y)"
]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "PKri",
+ "metadata": {
+ "marimo": {
+ "config": {
+ "expand_output": true
+ }
+ }
+ },
+ "outputs": [],
+ "source": [
+ "z = y + 1"
+ ]
}
],
"metadata": {
diff --git a/tests/_convert/ipynb/test_ipynb_idempotent.py b/tests/_convert/ipynb/test_ipynb_idempotent.py
index e08ac78394..f851dd2346 100644
--- a/tests/_convert/ipynb/test_ipynb_idempotent.py
+++ b/tests/_convert/ipynb/test_ipynb_idempotent.py
@@ -109,7 +109,8 @@ class TestSetupCell:
class TestCellConfig:
- """Cell configuration (hide_code, disabled) should survive round-trip."""
+ """Cell configuration (hide_code, disabled, expand_output) should
+ survive round-trip."""
def test_roundtrip(self) -> None:
assert_roundtrip("cell_config.py")
@@ -122,6 +123,10 @@ class TestCellConfig:
result = roundtrip(FIXTURES_PY / "cell_config.py")
assert "@app.cell(disabled=True)" in result
+ def test_expand_output_in_output(self) -> None:
+ result = roundtrip(FIXTURES_PY / "cell_config.py")
+ assert "@app.cell(expand_output=True)" in result
+
class TestMarkdownStringPrefix:
"""String prefix on mo.md() calls should survive round-trip."""
diff --git a/tests/_convert/markdown/test_markdown_conversion.py b/tests/_convert/markdown/test_markdown_conversion.py
index b13687c2e9..ddf992984d 100644
--- a/tests/_convert/markdown/test_markdown_conversion.py
+++ b/tests/_convert/markdown/test_markdown_conversion.py
@@ -436,6 +436,27 @@ def test_markdown_code_cell_attributes_are_unescaped() -> None:
assert 'name="a&quot;b &amp; &lt;c&gt;"' in markdown
+def test_markdown_cell_config_round_trips() -> None:
+ script_lines = (
+ '```python {.marimo expand_output="true" disabled="true"}',
+ "x = 1",
+ "```",
+ )
+
+ notebook_ir = convert_from_md_to_marimo_ir("\n".join(script_lines))
+
+ assert len(notebook_ir.cells) == 1
+ assert notebook_ir.cells[0].options["expand_output"] is True
+ assert notebook_ir.cells[0].options["disabled"] is True
+
+ markdown = convert_from_ir_to_markdown(
+ notebook_ir, filename="notebook.md", flavor="pymdown"
+ )
+
+ assert 'expand_output="true"' in markdown
+ assert 'disabled="true"' in markdown
+
+
def test_no_frontmatter() -> None:
script = dedent(
remove_empty_lines(
diff --git a/tests/_messaging/notebook/test_changes.py b/tests/_messaging/notebook/test_changes.py
index 9f9554441b..5165ae4799 100644
--- a/tests/_messaging/notebook/test_changes.py
+++ b/tests/_messaging/notebook/test_changes.py
@@ -54,6 +54,7 @@ class TestChangesFrozen:
column=None,
disabled=False,
hide_code=True,
+ expand_output=False,
)
with pytest.raises(AttributeError):
op.hide_code = False # type: ignore[misc]
diff --git a/tests/_messaging/notebook/test_document.py b/tests/_messaging/notebook/test_document.py
index b9f8b9adcc..708031bb3c 100644
--- a/tests/_messaging/notebook/test_document.py
+++ b/tests/_messaging/notebook/test_document.py
@@ -455,6 +455,7 @@ class TestCellVersion:
column=None,
disabled=True,
hide_code=False,
+ expand_output=False,
)
)
)
@@ -500,12 +501,31 @@ class TestSetConfig:
column=None,
disabled=False,
hide_code=True,
+ expand_output=False,
)
)
)
cfg = doc.get_cell(CellId_t("a")).config
assert cfg == CellConfig(column=None, disabled=False, hide_code=True)
+ def test_sets_expand_output(self) -> None:
+ doc = _doc("a")
+ doc.apply(
+ _tx(
+ SetConfig(
+ cell_id=CellId_t("a"),
+ column=None,
+ disabled=False,
+ hide_code=False,
+ expand_output=True,
+ )
+ )
+ )
+ cfg = doc.get_cell(CellId_t("a")).config
+ assert cfg == CellConfig(
+ column=None, disabled=False, hide_code=False, expand_output=True
+ )
+
def test_sets_disabled(self) -> None:
doc = _doc("a")
doc.apply(
@@ -515,6 +535,7 @@ class TestSetConfig:
column=None,
disabled=True,
hide_code=False,
+ expand_output=False,
)
)
)
@@ -531,7 +552,12 @@ class TestSetConfig:
id=CellId_t("a"),
code="",
name="__",
- config=CellConfig(column=2, disabled=True, hide_code=True),
+ config=CellConfig(
+ column=2,
+ disabled=True,
+ hide_code=True,
+ expand_output=True,
+ ),
)
]
)
@@ -542,11 +568,14 @@ class TestSetConfig:
column=0,
disabled=False,
hide_code=False,
+ expand_output=False,
)
)
)
cfg = doc.get_cell(CellId_t("a")).config
- assert cfg == CellConfig(column=0, disabled=False, hide_code=False)
+ assert cfg == CellConfig(
+ column=0, disabled=False, hide_code=False, expand_output=False
+ )
def test_column_reset_to_none(self) -> None:
doc = NotebookDocument(
@@ -566,6 +595,7 @@ class TestSetConfig:
column=None,
disabled=False,
hide_code=False,
+ expand_output=False,
)
)
)
diff --git a/tests/_messaging/notebook/test_reconcile.py b/tests/_messaging/notebook/test_reconcile.py
index e974b41188..22cac469dd 100644
--- a/tests/_messaging/notebook/test_reconcile.py
+++ b/tests/_messaging/notebook/test_reconcile.py
@@ -140,6 +140,7 @@ class TestSetProperties:
column=None,
disabled=False,
hide_code=False,
+ expand_output=False,
),
),
doc,
diff --git a/tests/_session/extensions/test_notification_listener_autosave.py b/tests/_session/extensions/test_notification_listener_autosave.py
index e1fb1d77e5..6ecfee3f4f 100644
--- a/tests/_session/extensions/test_notification_listener_autosave.py
+++ b/tests/_session/extensions/test_notification_listener_autosave.py
@@ -180,6 +180,7 @@ class TestKernelSourcedAutoSave:
column=None,
disabled=False,
hide_code=True,
+ expand_output=False,
)
),
)