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
user config: display.width (#1567)
Akshay Agrawalf4e40cbd0787
diff --git a/frontend/src/components/app-config/user-config-form.tsx b/frontend/src/components/app-config/user-config-form.tsxindex 1012479476..943e1e5e26 100644--- a/frontend/src/components/app-config/user-config-form.tsx+++ b/frontend/src/components/app-config/user-config-form.tsx@@ -10,7 +10,11 @@ import {FormLabel,FormMessage,} from "@/components/ui/form";-import { UserConfig, UserConfigSchema } from "../../core/config/config-schema";+import {+ APP_WIDTHS,+ UserConfig,+ UserConfigSchema,+} from "../../core/config/config-schema";import { Checkbox } from "../ui/checkbox";import { Input } from "../ui/input";import { saveUserConfig } from "../../core/network/requests";@@ -231,6 +235,35 @@ export const UserConfigForm: React.FC = () => {</div><div className="flex flex-col gap-3"><SettingSubtitle>Display</SettingSubtitle>+ <FormField+ control={form.control}+ name="display.default_width"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Default width</FormLabel>+ <FormControl>+ <NativeSelect+ data-testid="user-config-width-select"+ onChange={(e) => field.onChange(e.target.value)}+ value={field.value}+ disabled={field.disabled}+ className="inline-flex mr-2"+ >+ {APP_WIDTHS.map((option) => (+ <option value={option} key={option}>+ {option}+ </option>+ ))}+ </NativeSelect>+ </FormControl>+ <FormMessage />+ <FormDescription>+ The default app width for new notebooks; overridden by+ "width" in the application config.+ </FormDescription>+ </FormItem>+ )}+ /><FormFieldcontrol={form.control}name="display.theme"diff --git a/frontend/src/components/editor/controls/Controls.tsx b/frontend/src/components/editor/controls/Controls.tsxindex 091fbb68b2..44316cdaef 100644--- a/frontend/src/components/editor/controls/Controls.tsx+++ b/frontend/src/components/editor/controls/Controls.tsx@@ -97,7 +97,7 @@ export const Controls = ({<divclassName={cn(bottomRightControls,- appWidth === "normal" && "xl:flex-row items-end",+ appWidth === "compact" && "xl:flex-row items-end",)}>{closed ? (diff --git a/frontend/src/components/editor/renderers/vertical-layout/vertical-layout-wrapper.tsx b/frontend/src/components/editor/renderers/vertical-layout/vertical-layout-wrapper.tsxindex 1d67ef5762..c32915d0f7 100644--- a/frontend/src/components/editor/renderers/vertical-layout/vertical-layout-wrapper.tsx+++ b/frontend/src/components/editor/renderers/vertical-layout/vertical-layout-wrapper.tsx@@ -21,7 +21,7 @@ export const VerticalLayoutWrapper: React.FC<PropsWithChildren<Props>> = ({className={cn(// Large mobile bottom padding due to mobile browser navigation bar"m-auto pb-24 sm:pb-12",- appConfig.width === "normal" && "max-w-contentWidth min-w-[400px]",+ appConfig.width === "compact" && "max-w-contentWidth min-w-[400px]",appConfig.width === "medium" &&"max-w-contentWidthMedium min-w-[400px]",// Hide the cells for a fake loading effect, to avoid flickeringdiff --git a/frontend/src/core/config/__tests__/config-schema.test.ts b/frontend/src/core/config/__tests__/config-schema.test.tsindex a2484160ea..0caa6a0e24 100644--- a/frontend/src/core/config/__tests__/config-schema.test.ts+++ b/frontend/src/core/config/__tests__/config-schema.test.ts@@ -6,7 +6,7 @@ test("default AppConfig", () => {const defaultConfig = AppConfigSchema.parse({});expect(defaultConfig).toMatchInlineSnapshot(`{- "width": "normal",+ "width": "medium",}`);});@@ -36,6 +36,7 @@ test("default UserConfig - empty", () => {"display": {"cell_output": "above","code_editor_font_size": 14,+ "default_width": "medium","theme": "light",},"experimental": {},@@ -83,6 +84,7 @@ test("default UserConfig - one level", () => {"display": {"cell_output": "above","code_editor_font_size": 14,+ "default_width": "medium","theme": "light",},"experimental": {},diff --git a/frontend/src/core/config/config-schema.ts b/frontend/src/core/config/config-schema.tsindex ed28d63a8e..92c1a76ff1 100644--- a/frontend/src/core/config/config-schema.ts+++ b/frontend/src/core/config/config-schema.ts@@ -13,6 +13,11 @@ export const PackageManagerNames = [] as const;export type PackageManagerName = (typeof PackageManagerNames)[number];+export const APP_WIDTHS = ["compact", "medium", "full"] as const;+/**+ * normal == compact, but normal is deprecated+ */+const VALID_APP_WIDTHS = ["normal", ...APP_WIDTHS] as const;export const UserConfigSchema = z.object({completion: z@@ -60,6 +65,15 @@ export const UserConfigSchema = ztheme: z.enum(["light", "dark", "system"]).default("light"),code_editor_font_size: z.number().nonnegative().default(14),cell_output: z.enum(["above", "below"]).default("above"),+ default_width: z+ .enum(VALID_APP_WIDTHS)+ .default("medium")+ .transform((width) => {+ if (width === "normal") {+ return "compact";+ }+ return width;+ }),}).default({}),package_management: z@@ -103,7 +117,6 @@ export type SaveConfig = UserConfig["save"];export type CompletionConfig = UserConfig["completion"];export type KeymapConfig = UserConfig["keymap"];-export const APP_WIDTHS = ["normal", "medium", "full"] as const;export const AppTitleSchema = z.string().regex(new RegExp("^[A-Za-z0-9-_' ]*$"), {@@ -111,10 +124,18 @@ export const AppTitleSchema = z});export const AppConfigSchema = z.object({- width: z.enum(APP_WIDTHS).default("normal"),+ width: z+ .enum(VALID_APP_WIDTHS)+ .default("medium")+ .transform((width) => {+ if (width === "normal") {+ return "compact";+ }+ return width;+ }),app_title: AppTitleSchema.nullish(),})- .default({ width: "normal" });+ .default({ width: "medium" });export type AppConfig = z.infer<typeof AppConfigSchema>;export function parseAppConfig() {diff --git a/frontend/src/stories/cell.stories.tsx b/frontend/src/stories/cell.stories.tsxindex 6221a0410d..adf067fb72 100644--- a/frontend/src/stories/cell.stories.tsx+++ b/frontend/src/stories/cell.stories.tsx@@ -64,6 +64,7 @@ const props: CellProps = {theme: "light",code_editor_font_size: 14,cell_output: "above",+ default_width: "medium",},runtime: {auto_instantiate: true,diff --git a/marimo/_ast/app.py b/marimo/_ast/app.pyindex 342660e052..306ef4b61b 100644--- a/marimo/_ast/app.py+++ b/marimo/_ast/app.py@@ -11,7 +11,6 @@ from typing import (Callable,Iterable,Iterator,- Literal,Mapping,Optional,)@@ -31,6 +30,7 @@ from marimo._ast.errors import (MultipleDefinitionError,UnparsableError,)+from marimo._config.config import WidthTypefrom marimo._dependencies.dependencies import DependencyManagerfrom marimo._messaging.mimetypes import KnownMimeTypefrom marimo._messaging.types import NoopStream@@ -54,7 +54,7 @@ class _AppConfig:a single marimo program."""- width: Literal["normal", "medium", "full"] = "normal"+ width: WidthType = "compact"app_title: Optional[str] = None# The file path of the layout file, relative to the app file.diff --git a/marimo/_config/config.py b/marimo/_config/config.pyindex ba474a2baa..81fe0aaaff 100644--- a/marimo/_config/config.py+++ b/marimo/_config/config.py@@ -88,6 +88,11 @@ class RuntimeConfig(TypedDict):on_cell_change: OnCellChangeType+# TODO(akshayka): remove normal, migrate to compact+# normal == compact+WidthType = Literal["normal", "compact", "medium", "full"]++@mddocclass DisplayConfig(TypedDict):"""Configuration for display.@@ -102,6 +107,7 @@ class DisplayConfig(TypedDict):theme: Literal["light", "dark", "system"]code_editor_font_size: intcell_output: Literal["above", "below"]+ default_width: WidthType@mddoc@@ -190,6 +196,7 @@ DEFAULT_CONFIG: MarimoConfig = {"theme": "light","code_editor_font_size": 14,"cell_output": "above",+ "default_width": "medium",},"formatting": {"line_length": 79},"keymap": {"preset": "default", "overrides": {}},diff --git a/marimo/_islands/island_generator.py b/marimo/_islands/island_generator.pyindex 5d62cb9338..801d76a195 100644--- a/marimo/_islands/island_generator.py+++ b/marimo/_islands/island_generator.py@@ -433,7 +433,7 @@ class MarimoIslandGenerator:margin = "auto"if max_width is None:width = self._config.width- if width == "normal":+ if width == "compact" or width == "normal":max_width = "740px"elif width == "medium":max_width = "1110px"diff --git a/marimo/_pyodide/bootstrap.py b/marimo/_pyodide/bootstrap.pyindex 517624424c..bec853e35a 100644--- a/marimo/_pyodide/bootstrap.py+++ b/marimo/_pyodide/bootstrap.py@@ -47,7 +47,14 @@ def create_session(def write_kernel_message(op: KernelMessage) -> None:message_callback(json.dumps({"op": op[0], "data": op[1]}))- app_file_manager = AppFileManager(filename=filename)+ # Lazy import to decrease startup time+ from marimo._config.config import merge_default_config++ user_config = merge_default_config(user_config)+ app_file_manager = AppFileManager(+ filename=filename,+ default_width=user_config["display"]["default_width"],+ )app = app_file_manager.app# We want this message to be performant, so any expensive operations@@ -71,8 +78,6 @@ def create_session())- # Lazy import to increase startup time- from marimo._config.config import merge_default_configfrom marimo._pyodide.pyodide_session import PyodideBridge, PyodideSessionsession = PyodideSession(@@ -80,7 +85,7 @@ def create_session(SessionMode.EDIT,write_kernel_message,AppMetadata(query_params=query_params, filename=filename, cli_args={}),- merge_default_config(user_config),+ user_config,)bridge = PyodideBridge(session)diff --git a/marimo/_server/file_manager.py b/marimo/_server/file_manager.pyindex d27e2ac9c7..7795f70d80 100644--- a/marimo/_server/file_manager.py+++ b/marimo/_server/file_manager.py@@ -8,23 +8,25 @@ from marimo import _loggersfrom marimo._ast import codegenfrom marimo._ast.app import App, InternalApp, _AppConfigfrom marimo._ast.cell import CellConfig+from marimo._config.config import WidthTypefrom marimo._runtime.layout.layout import (LayoutConfig,read_layout_config,save_layout_config,)from marimo._server.api.status import HTTPException, HTTPStatus-from marimo._server.models.models import (- SaveRequest,-)+from marimo._server.models.models import SaveRequestfrom marimo._server.utils import canonicalize_filenameLOGGER = _loggers.marimo_logger()class AppFileManager:- def __init__(self, filename: Optional[str]) -> None:+ def __init__(+ self, filename: Optional[str], default_width: WidthType | None = None+ ) -> None:self.filename = filename+ self._default_width: WidthType | None = default_widthself.app = self._load_app(self.path)@staticmethod@@ -115,12 +117,17 @@ class AppFileManager:if self._is_unnamed():self.rename(filename)- @staticmethod- def _load_app(path: Optional[str]) -> InternalApp:+ def _load_app(self, path: Optional[str]) -> InternalApp:"""Read the app from the file."""app = codegen.get_app(path)if app is None:- empty_app = InternalApp(App())+ kwargs = (+ {"width": self._default_width}+ if self._default_width is not None+ # App decides its own default width+ else {}+ )+ empty_app = InternalApp(App(**kwargs))empty_app.cell_manager.register_cell(cell_id=None,code="",diff --git a/marimo/_server/file_router.py b/marimo/_server/file_router.pyindex 8b91e8d63e..337b79f25b 100644--- a/marimo/_server/file_router.py+++ b/marimo/_server/file_router.py@@ -6,6 +6,7 @@ import osfrom typing import List, Optionalfrom marimo import _loggers+from marimo._config.config import WidthTypefrom marimo._server.api.status import HTTPException, HTTPStatusfrom marimo._server.file_manager import AppFileManagerfrom marimo._server.models.home import MarimoFile@@ -60,29 +61,35 @@ class AppFileRouter(abc.ABC):def new_file() -> AppFileRouter:return NewFileAppFileRouter()- def get_single_app_file_manager(self) -> AppFileManager:+ def get_single_app_file_manager(+ self, default_width: WidthType | None = None+ ) -> AppFileManager:key = self.get_unique_file_key()assert key is not None, "Expected a single file"- return self.get_file_manager(key)+ return self.get_file_manager(key, default_width)- def get_file_manager(self, key: MarimoFileKey) -> AppFileManager:+ def get_file_manager(+ self,+ key: MarimoFileKey,+ default_width: WidthType | None = None,+ ) -> AppFileManager:"""Given a key, return an AppFileManager."""if key.startswith(AppFileRouter.NEW_FILE):- return AppFileManager(None)+ return AppFileManager(None, default_width)for file in self.files:if file.path == key:- return AppFileManager(file.path)+ return AppFileManager(file.path, default_width)# Absolute pathif os.path.isabs(key):- return AppFileManager(key)+ return AppFileManager(key, default_width)# Relative pathif os.path.exists(key):- return AppFileManager(key)+ return AppFileManager(key, default_width)raise HTTPException(status_code=HTTPStatus.NOT_FOUND,diff --git a/marimo/_server/sessions.py b/marimo/_server/sessions.pyindex 985aa58084..9f25e0fdac 100644--- a/marimo/_server/sessions.py+++ b/marimo/_server/sessions.py@@ -45,16 +45,10 @@ from marimo._runtime.requests import (SetUIElementValueRequest,)from marimo._server.exceptions import InvalidSessionException-from marimo._server.file_manager import (- AppFileManager,-)+from marimo._server.file_manager import AppFileManagerfrom marimo._server.file_router import AppFileRouter, MarimoFileKeyfrom marimo._server.ids import SessionId-from marimo._server.model import (- ConnectionState,- SessionConsumer,- SessionMode,-)+from marimo._server.model import ConnectionState, SessionConsumer, SessionModefrom marimo._server.models.models import InstantiateRequestfrom marimo._server.recents import RecentFilesManagerfrom marimo._server.session.session_view import SessionView@@ -492,7 +486,11 @@ class SessionManager:self.auth_token = AuthToken.random()self.skew_protection_token = SkewProtectionToken.random()else:- app = file_router.get_single_app_file_manager().app+ app = file_router.get_single_app_file_manager(+ default_width=user_config_manager.get_config()["display"][+ "default_width"+ ]+ ).appcodes = "".join(code for code in app.cell_manager.codes())# Because run-mode is read-only and we could have multiple# servers for the same app (going to sleep or autoscaling),@@ -504,7 +502,12 @@ class SessionManager:"""Get the app manager for the given key."""- return self.file_router.get_file_manager(key)+ return self.file_router.get_file_manager(+ key,+ default_width=self.user_config_manager.get_config()["display"][+ "default_width"+ ],+ )def create_session(self,@@ -516,7 +519,12 @@ class SessionManager:"""Create a new session"""LOGGER.debug("Creating new session for id %s", session_id)if session_id not in self.sessions:- app_file_manager = self.file_router.get_file_manager(file_key)+ app_file_manager = self.file_router.get_file_manager(+ file_key,+ default_width=self.user_config_manager.get_config()["display"][+ "default_width"+ ],+ )if app_file_manager.path:self.recents.touch(app_file_manager.path)diff --git a/marimo/_server/templates/templates.py b/marimo/_server/templates/templates.pyindex ac8d45d2cb..38a69c98db 100644--- a/marimo/_server/templates/templates.py+++ b/marimo/_server/templates/templates.py@@ -61,7 +61,6 @@ def notebook_page_template("{{ mode }}","read" if mode == SessionMode.RUN else "edit",)-return htmldiff --git a/tests/_ast/test_app.py b/tests/_ast/test_app.pyindex 9368d5bf9a..30d982057c 100644--- a/tests/_ast/test_app.py+++ b/tests/_ast/test_app.py@@ -278,7 +278,7 @@ class TestApp:@staticmethoddef test_app_width_default() -> None:app = App()- assert app._config.width == "normal"+ assert app._config.width == "compact"@staticmethoddef test_app_config_extra_args_ignored() -> None:diff --git a/tests/_server/templates/snapshots/export1.txt b/tests/_server/templates/snapshots/export1.txtindex d8bef7c8c6..5a0404c110 100644--- a/tests/_server/templates/snapshots/export1.txt+++ b/tests/_server/templates/snapshots/export1.txt@@ -56,8 +56,8 @@<marimo-filename hidden>notebook.py</marimo-filename><marimo-mode data-mode='read' hidden></marimo-mode><marimo-version data-version='0.0.0' hidden></marimo-version>- <marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"cell_output": "above", "code_editor_font_size": 14, "theme": "light"}, "formatting": {"line_length": 79}, "keymap": {"overrides": {}, "preset": "default"}, "package_management": {"manager": "pip"}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun"}, "save": {"autosave": "after_delay", "autosave_delay": 1000, "format_on_save": false}, "server": {"browser": "default", "follow_symlink": false}}' hidden></marimo-user-config>- <marimo-app-config data-config='{"app_title": null, "layout_file": null, "width": "normal"}' hidden></marimo-app-config>+ <marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"cell_output": "above", "code_editor_font_size": 14, "default_width": "medium", "theme": "light"}, "formatting": {"line_length": 79}, "keymap": {"overrides": {}, "preset": "default"}, "package_management": {"manager": "pip"}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun"}, "save": {"autosave": "after_delay", "autosave_delay": 1000, "format_on_save": false}, "server": {"browser": "default", "follow_symlink": false}}' hidden></marimo-user-config>+ <marimo-app-config data-config='{"app_title": null, "layout_file": null, "width": "compact"}' hidden></marimo-app-config><marimo-server-token data-token='token' hidden></marimo-server-token><title>notebook</title><script type="module" crossorigin crossorigin="anonymous" src="https://cdn.jsdelivr.net/npm/@marimo-team/[email protected]/dist/assets/index.js""></script>diff --git a/tests/_server/templates/snapshots/export2.txt b/tests/_server/templates/snapshots/export2.txtindex 51176d3875..4aa6df447d 100644--- a/tests/_server/templates/snapshots/export2.txt+++ b/tests/_server/templates/snapshots/export2.txt@@ -56,8 +56,8 @@<marimo-filename hidden></marimo-filename><marimo-mode data-mode='read' hidden></marimo-mode><marimo-version data-version='0.0.0' hidden></marimo-version>- <marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"cell_output": "above", "code_editor_font_size": 14, "theme": "light"}, "formatting": {"line_length": 79}, "keymap": {"overrides": {}, "preset": "default"}, "package_management": {"manager": "pip"}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun"}, "save": {"autosave": "after_delay", "autosave_delay": 1000, "format_on_save": false}, "server": {"browser": "default", "follow_symlink": false}}' hidden></marimo-user-config>- <marimo-app-config data-config='{"app_title": null, "layout_file": null, "width": "normal"}' hidden></marimo-app-config>+ <marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"cell_output": "above", "code_editor_font_size": 14, "default_width": "medium", "theme": "light"}, "formatting": {"line_length": 79}, "keymap": {"overrides": {}, "preset": "default"}, "package_management": {"manager": "pip"}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun"}, "save": {"autosave": "after_delay", "autosave_delay": 1000, "format_on_save": false}, "server": {"browser": "default", "follow_symlink": false}}' hidden></marimo-user-config>+ <marimo-app-config data-config='{"app_title": null, "layout_file": null, "width": "compact"}' hidden></marimo-app-config><marimo-server-token data-token='token' hidden></marimo-server-token><title>marimo</title><script type="module" crossorigin crossorigin="anonymous" src="https://cdn.jsdelivr.net/npm/@marimo-team/[email protected]/dist/assets/index.js""></script>diff --git a/tests/_server/templates/snapshots/export3.txt b/tests/_server/templates/snapshots/export3.txtindex aa88bab164..20a063cdd9 100644--- a/tests/_server/templates/snapshots/export3.txt+++ b/tests/_server/templates/snapshots/export3.txt@@ -56,8 +56,8 @@<marimo-filename hidden>notebook.py</marimo-filename><marimo-mode data-mode='read' hidden></marimo-mode><marimo-version data-version='0.0.0' hidden></marimo-version>- <marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"cell_output": "above", "code_editor_font_size": 14, "theme": "light"}, "formatting": {"line_length": 79}, "keymap": {"overrides": {}, "preset": "default"}, "package_management": {"manager": "pip"}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun"}, "save": {"autosave": "after_delay", "autosave_delay": 1000, "format_on_save": false}, "server": {"browser": "default", "follow_symlink": false}}' hidden></marimo-user-config>- <marimo-app-config data-config='{"app_title": null, "layout_file": null, "width": "normal"}' hidden></marimo-app-config>+ <marimo-user-config data-config='{"completion": {"activate_on_typing": true, "copilot": false}, "display": {"cell_output": "above", "code_editor_font_size": 14, "default_width": "medium", "theme": "light"}, "formatting": {"line_length": 79}, "keymap": {"overrides": {}, "preset": "default"}, "package_management": {"manager": "pip"}, "runtime": {"auto_instantiate": true, "auto_reload": "off", "on_cell_change": "autorun"}, "save": {"autosave": "after_delay", "autosave_delay": 1000, "format_on_save": false}, "server": {"browser": "default", "follow_symlink": false}}' hidden></marimo-user-config>+ <marimo-app-config data-config='{"app_title": null, "layout_file": null, "width": "compact"}' hidden></marimo-app-config><marimo-server-token data-token='token' hidden></marimo-server-token><title>notebook</title><script type="module" crossorigin crossorigin="anonymous" src="https://cdn.jsdelivr.net/npm/@marimo-team/[email protected]/dist/assets/index.js""></script>