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: add disable auto-run config (#142)

Myles Scolnickd16996061e94
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index e6316f9bee..4b4fad3fd2 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -80,6 +80,8 @@ export const App: React.FC<AppProps> = ({ userConfig, appConfig }) => {
}, []);
const { connStatus } = useMarimoWebSocket({
+ autoInstantiate:
+ userConfig.runtime.auto_instantiate || viewState.mode === "read",
setCells,
setInitialCodes: setSavedCodes,
setInitialConfigs: setSavedConfigs,
diff --git a/frontend/src/components/app-config/app-config-form.tsx b/frontend/src/components/app-config/app-config-form.tsx
index 75c3dc7040..91d47309c3 100644
--- a/frontend/src/components/app-config/app-config-form.tsx
+++ b/frontend/src/components/app-config/app-config-form.tsx
@@ -13,6 +13,7 @@ import { toast } from "../ui/use-toast";
import { useAppConfig } from "@/core/state/config";
import { Switch } from "@/components/ui/switch";
import { saveAppConfig } from "@/core/network/requests";
+import { SettingTitle } from "./common";
export const AppConfigForm: React.FC = () => {
const [config, setConfig] = useAppConfig();
@@ -36,7 +37,11 @@ export const AppConfigForm: React.FC = () => {
return (
<Form {...form}>
- <form onChange={form.handleSubmit(onSubmit)}>
+ <form
+ onChange={form.handleSubmit(onSubmit)}
+ className="flex flex-col gap-4"
+ >
+ <SettingTitle>Application config</SettingTitle>
<FormField
control={form.control}
name="width"
diff --git a/frontend/src/components/app-config/common.tsx b/frontend/src/components/app-config/common.tsx
new file mode 100644
index 0000000000..ebd0930fb0
--- /dev/null
+++ b/frontend/src/components/app-config/common.tsx
@@ -0,0 +1,10 @@
+/* Copyright 2023 Marimo. All rights reserved. */
+import { PropsWithChildren } from "react";
+
+export const SettingTitle: React.FC<PropsWithChildren> = ({ children }) => {
+ return (
+ <div className="text-sm font-semibold text-muted-foreground uppercase tracking-wide">
+ {children}
+ </div>
+ );
+};
diff --git a/frontend/src/components/app-config/theme-toggle.tsx b/frontend/src/components/app-config/theme-toggle.tsx
index f218033c2b..9c15467cbf 100644
--- a/frontend/src/components/app-config/theme-toggle.tsx
+++ b/frontend/src/components/app-config/theme-toggle.tsx
@@ -12,19 +12,16 @@ export const ThemeToggle: React.FC = () => {
}
return (
- <>
- <div className="h-px bg-gray-200 dark:bg-gray-700" />
- <FormItem className="flex flex-row items-start space-x-2 space-y-0">
- <FormControl>
- <Checkbox
- checked={theme === "dark"}
- onCheckedChange={(checked) => {
- return setTheme(checked === true ? "dark" : "light");
- }}
- />
- </FormControl>
- <FormLabel className="font-normal">Dark mode</FormLabel>
- </FormItem>
- </>
+ <FormItem className="flex flex-row items-start space-x-2 space-y-0">
+ <FormControl>
+ <Checkbox
+ checked={theme === "dark"}
+ onCheckedChange={(checked) => {
+ return setTheme(checked === true ? "dark" : "light");
+ }}
+ />
+ </FormControl>
+ <FormLabel className="font-normal">Dark mode</FormLabel>
+ </FormItem>
);
};
diff --git a/frontend/src/components/app-config/user-config-form.tsx b/frontend/src/components/app-config/user-config-form.tsx
index 066c14d071..bdbc21cd4c 100644
--- a/frontend/src/components/app-config/user-config-form.tsx
+++ b/frontend/src/components/app-config/user-config-form.tsx
@@ -21,6 +21,7 @@ import { NativeSelect } from "../ui/native-select";
import { KEYMAP_PRESETS } from "@/core/codemirror/keymaps/keymaps";
import { CopilotConfig } from "@/core/codemirror/copilot/copilot-config";
import { Switch } from "../ui/switch";
+import { SettingTitle } from "./common";
export const UserConfigForm: React.FC = () => {
const [config, setConfig] = useUserConfig();
@@ -45,120 +46,145 @@ export const UserConfigForm: React.FC = () => {
<Form {...form}>
<form
onChange={form.handleSubmit(onSubmit)}
- className="flex flex-col gap-4"
+ className="flex flex-col gap-5"
>
- <FormField
- control={form.control}
- name="save.autosave"
- render={({ field }) => (
- <FormItem className="flex flex-row items-start space-x-2 space-y-0">
- <FormControl>
- <Checkbox
- checked={field.value === "after_delay"}
- onCheckedChange={(checked) => {
- return field.onChange(
- checked === true ? "after_delay" : "off"
- );
- }}
- />
- </FormControl>
- <FormLabel className="font-normal">Autosave</FormLabel>
- </FormItem>
- )}
- />
- <FormField
- control={form.control}
- name="save.autosave_delay"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Autosave delay (seconds)</FormLabel>
- <FormControl>
- <Input
- type="number"
- disabled={form.getValues("save.autosave") !== "after_delay"}
- {...field}
- value={field.value / 1000}
- min={1}
- onChange={(e) =>
- field.onChange(Number.parseInt(e.target.value) * 1000)
- }
- />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- <FormField
- control={form.control}
- name="completion.activate_on_typing"
- render={({ field }) => (
- <div className="flex flex-col space-y-1">
+ <div className="flex flex-col gap-3">
+ <SettingTitle>Editor</SettingTitle>
+ <FormField
+ control={form.control}
+ name="save.autosave"
+ render={({ field }) => (
<FormItem className="flex flex-row items-start space-x-2 space-y-0">
<FormControl>
<Checkbox
- checked={field.value}
+ checked={field.value === "after_delay"}
onCheckedChange={(checked) => {
- return field.onChange(Boolean(checked));
+ return field.onChange(
+ checked === true ? "after_delay" : "off"
+ );
}}
/>
</FormControl>
- <FormLabel className="font-normal">
- Trigger autocomplete while typing
- </FormLabel>
+ <FormLabel className="font-normal">Auto-save</FormLabel>
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="save.autosave_delay"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Auto-save delay (seconds)</FormLabel>
+ <FormControl>
+ <Input
+ type="number"
+ className="m-0"
+ disabled={form.getValues("save.autosave") !== "after_delay"}
+ {...field}
+ value={field.value / 1000}
+ min={1}
+ onChange={(e) =>
+ field.onChange(Number.parseInt(e.target.value) * 1000)
+ }
+ />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="completion.activate_on_typing"
+ render={({ field }) => (
+ <div className="flex flex-col space-y-1">
+ <FormItem className="flex flex-row items-start space-x-2 space-y-0">
+ <FormControl>
+ <Checkbox
+ checked={field.value}
+ onCheckedChange={(checked) => {
+ return field.onChange(Boolean(checked));
+ }}
+ />
+ </FormControl>
+ <FormLabel className="font-normal">
+ Trigger autocomplete while typing
+ </FormLabel>
+ </FormItem>
+ <FormDescription>
+ When unchecked, code completion is still available through a
+ hotkey.
+ </FormDescription>
+ </div>
+ )}
+ />
+ <FormField
+ control={form.control}
+ name="keymap.preset"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Keymap</FormLabel>
+ <FormControl>
+ <NativeSelect
+ onChange={(e) => field.onChange(e.target.value)}
+ value={field.value}
+ >
+ {KEYMAP_PRESETS.map((option) => (
+ <option value={option} key={option}>
+ {option}
+ </option>
+ ))}
+ </NativeSelect>
+ </FormControl>
+ <FormMessage />
</FormItem>
- <FormDescription>
- When unchecked, code completion is still available through a
- hotkey.
- </FormDescription>
- </div>
- )}
- />
- <FormField
- control={form.control}
- name="keymap.preset"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Keymap</FormLabel>
- <FormControl>
- <NativeSelect
- onChange={(e) => field.onChange(e.target.value)}
- value={field.value}
- >
- {KEYMAP_PRESETS.map((option) => (
- <option value={option} key={option}>
- {option}
- </option>
- ))}
- </NativeSelect>
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- <div className="h-px bg-gray-200 dark:bg-gray-700" />
- <div className="text-sm font-medium">GitHub Copilot</div>
- <FormField
- control={form.control}
- name="completion.copilot"
- render={({ field }) => (
- <div className="flex flex-col gap-2">
- <FormItem className="flex flex-row items-center space-x-2 space-y-0">
+ )}
+ />
+ <ThemeToggle />
+ </div>
+ <div className="flex flex-col gap-3">
+ <SettingTitle>Runtime</SettingTitle>
+ <FormField
+ control={form.control}
+ name="runtime.auto_instantiate"
+ render={({ field }) => (
+ <FormItem className="flex flex-row items-start space-x-2 space-y-0">
<FormControl>
- <Switch
- size={"sm"}
+ <Checkbox
checked={field.value}
- onCheckedChange={(checked) => {
- return field.onChange(Boolean(checked));
- }}
+ onCheckedChange={field.onChange}
/>
</FormControl>
- <FormLabel className="font-normal flex">Enable</FormLabel>
+ <FormLabel className="font-normal">
+ Auto-run on startup
+ </FormLabel>
</FormItem>
- {field.value && <CopilotConfig />}
- </div>
- )}
- />
- <ThemeToggle />
+ )}
+ />
+ </div>
+ <div className="flex flex-col gap-3">
+ <SettingTitle>GitHub Copilot</SettingTitle>
+ <FormField
+ control={form.control}
+ name="completion.copilot"
+ render={({ field }) => (
+ <div className="flex flex-col gap-2">
+ <FormItem className="flex flex-row items-center space-x-2 space-y-0">
+ <FormControl>
+ <Switch
+ size={"sm"}
+ checked={field.value}
+ onCheckedChange={(checked) => {
+ return field.onChange(Boolean(checked));
+ }}
+ />
+ </FormControl>
+ <FormLabel className="font-normal flex">Enable</FormLabel>
+ </FormItem>
+ {field.value && <CopilotConfig />}
+ </div>
+ )}
+ />
+ </div>
</form>
</Form>
);
diff --git a/frontend/src/core/config/config.ts b/frontend/src/core/config/config.ts
index d0fbcc5352..973521d180 100644
--- a/frontend/src/core/config/config.ts
+++ b/frontend/src/core/config/config.ts
@@ -20,6 +20,11 @@ export const UserConfigSchema = z
keymap: z.object({
preset: z.enum(["default", "vim"]).default("default"),
}),
+ runtime: z
+ .object({
+ auto_instantiate: z.boolean(),
+ })
+ .default({ auto_instantiate: true }),
experimental: z
.object({
theming: z.boolean().optional(),
diff --git a/frontend/src/core/websocket/useMarimoWebSocket.tsx b/frontend/src/core/websocket/useMarimoWebSocket.tsx
index d9bd556705..e12eabdb7f 100644
--- a/frontend/src/core/websocket/useMarimoWebSocket.tsx
+++ b/frontend/src/core/websocket/useMarimoWebSocket.tsx
@@ -26,11 +26,18 @@ import { renderHTML } from "@/plugins/core/RenderHTML";
*/
export function useMarimoWebSocket(opts: {
sessionId: string;
+ autoInstantiate: boolean;
setCells: (cells: CellState[]) => void;
setInitialCodes: (codes: string[]) => void;
setInitialConfigs: (cellConfigs: CellConfig[]) => void;
}) {
- const { sessionId, setCells, setInitialCodes, setInitialConfigs } = opts;
+ const {
+ autoInstantiate,
+ sessionId,
+ setCells,
+ setInitialCodes,
+ setInitialConfigs,
+ } = opts;
const { showBoundary } = useErrorBoundary();
const { handleCellMessage } = useCellActions();
@@ -70,6 +77,7 @@ export function useMarimoWebSocket(opts: {
createCell({
key: CellId.create(),
code,
+ edited: !autoInstantiate,
name: names[i],
config: configs[i],
})
@@ -106,9 +114,13 @@ export function useMarimoWebSocket(opts: {
);
});
// Send the instantiate message
- sendInstantiate({ objectIds, values }).catch((error) => {
- showBoundary(new Error("Failed to instantiate", { cause: error }));
- });
+ if (autoInstantiate) {
+ sendInstantiate({ objectIds, values }).catch((error) => {
+ showBoundary(
+ new Error("Failed to instantiate", { cause: error })
+ );
+ });
+ }
return;
}
case "completed-run":
diff --git a/frontend/src/css/common.css b/frontend/src/css/common.css
index 45047ad047..4b439dde61 100644
--- a/frontend/src/css/common.css
+++ b/frontend/src/css/common.css
@@ -39,6 +39,7 @@ body.printing #App {
a.hyperlink {
@apply text-link;
}
+
a.hyperlink:hover {
text-decoration: underline;
}
diff --git a/frontend/src/stories/cell.stories.tsx b/frontend/src/stories/cell.stories.tsx
index 604772da53..1ce26303f6 100644
--- a/frontend/src/stories/cell.stories.tsx
+++ b/frontend/src/stories/cell.stories.tsx
@@ -49,6 +49,9 @@ const props: CellProps = {
autosave: "off",
autosave_delay: 1000,
},
+ runtime: {
+ auto_instantiate: true,
+ },
keymap: {
preset: "default",
},
diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts
index f083f8d503..1c09fd21af 100644
--- a/frontend/vite.config.ts
+++ b/frontend/vite.config.ts
@@ -21,6 +21,7 @@ const htmlDevPlugin = (): Plugin => {
save: {
autosave: "off",
autosave_delay: 0,
+ auto_instantiate: true,
},
keymap: {
preset: "default",
diff --git a/marimo/_config/config.py b/marimo/_config/config.py
index bdf0367cbc..4ec7275758 100644
--- a/marimo/_config/config.py
+++ b/marimo/_config/config.py
@@ -60,6 +60,21 @@ class KeymapConfig(TypedDict, total=False):
preset: Literal["default", "vim"]
+@mddoc
+class RuntimeConfig(TypedDict, total=False):
+ """Configuration for runtime.
+
+ **Keys.**
+
+ - `auto_instantiate`: if `False`, cells won't automatically
+ run on startup. This only applies when editing a notebook,
+ and not when running as an application.
+ The default is `True`.
+ """
+
+ auto_instantiate: bool
+
+
@mddoc
class MarimoConfig(TypedDict, total=False):
"""Configuration for the marimo editor.
@@ -90,6 +105,7 @@ class MarimoConfig(TypedDict, total=False):
completion: CompletionConfig
save: SaveConfig
keymap: KeymapConfig
+ runtime: RuntimeConfig
experimental: Dict[str, Any]
@@ -97,6 +113,7 @@ DEFAULT_CONFIG: MarimoConfig = {
"completion": {"activate_on_typing": True, "copilot": False},
"save": {"autosave": "after_delay", "autosave_delay": 1000},
"keymap": {"preset": "default"},
+ "runtime": {"auto_instantiate": True},
}
_USER_CONFIG: Optional[MarimoConfig] = None