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
improve: Home button in notebook menu (#1997)
Wasim Sandhueff559f8a022
diff --git a/docs/apps/embedding_numbers.py b/docs/apps/embedding_numbers.pyindex 0f7e59ae10..cb5e402a88 100644--- a/docs/apps/embedding_numbers.py+++ b/docs/apps/embedding_numbers.py@@ -1,22 +1,23 @@import marimo-__generated_with = "0.0.5"+__generated_with = "0.7.19"app = marimo.App()@app.celldef __(mo):mo.md(- """# Embedding MNIST+ """+ # Embedding MNIST- This app shows how to use the function `pymde.preserve_neighbors`- to produce embeddings that highlight the local structure of your- data, using MNIST as a case study. In these embeddings similar- digits are near each other, and dissimilar digits are not near each other.+ This app shows how to use the function `pymde.preserve_neighbors`+ to produce embeddings that highlight the local structure of your+ data, using MNIST as a case study. In these embeddings similar+ digits are near each other, and dissimilar digits are not near each other.- ## Data- The data we'll embed are 70,000 28x28 grayscale images of handwritten- digits:+ ## Data+ The data we'll embed are 70,000 28x28 grayscale images of handwritten+ digits:""")returndiff --git a/frontend/src/components/editor/actions/useNotebookActions.tsx b/frontend/src/components/editor/actions/useNotebookActions.tsxindex 5616bec141..99f73f7ed2 100644--- a/frontend/src/components/editor/actions/useNotebookActions.tsx+++ b/frontend/src/components/editor/actions/useNotebookActions.tsx@@ -21,6 +21,7 @@ import {KeyboardIcon,Undo2Icon,FileIcon,+ Home,} from "lucide-react";import { commandPaletteAtom } from "../controls/command-palette";import { useCellActions, useNotebook } from "@/core/cells/cells";@@ -299,6 +300,15 @@ export function useNotebookActions() {{divider: true,+ icon: <Home size={14} strokeWidth={1.5} />,+ label: "Return home",+ hidden: !location.search.includes("file"),+ handle: () => {+ window.location.href = document.baseURI;+ },+ },++ {icon: <PowerSquareIcon size={14} strokeWidth={1.5} />,label: "Restart kernel",variant: "danger",diff --git a/frontend/src/components/pages/home-page.tsx b/frontend/src/components/pages/home-page.tsxindex 02493e16e9..413926925c 100644--- a/frontend/src/components/pages/home-page.tsx+++ b/frontend/src/components/pages/home-page.tsx@@ -131,10 +131,12 @@ const HomePage: React.FC = () => {<NotebookListheader={<Header Icon={PlayCircleIcon}>Running notebooks</Header>}files={[...running.values()]}+ openNewTab={false}/><NotebookListheader={<Header Icon={ClockIcon}>Recent notebooks</Header>}files={recents.files}+ openNewTab={true}/><div className="flex flex-col gap-2"><Header@@ -338,7 +340,8 @@ const FolderArrow = ({ node }: { node: NodeApi<FileInfo> }) => {const NotebookList: React.FC<{header: React.ReactNode;files: MarimoFile[];-}> = ({ header, files }) => {+ openNewTab: boolean;+}> = ({ header, files, openNewTab }) => {if (files.length === 0) {return null;}@@ -348,7 +351,13 @@ const NotebookList: React.FC<{{header}<div className="flex flex-col divide-y divide-[var(--slate-3)] border rounded overflow-hidden max-h-[48rem] overflow-y-auto shadow-sm bg-background">{files.map((file) => {- return <MarimoFileComponent key={file.path} file={file} />;+ return (+ <MarimoFileComponent+ key={file.path}+ file={file}+ openNewTab={openNewTab}+ />+ );})}</div></div>@@ -371,7 +380,13 @@ const Header: React.FC<{);};-const MarimoFileComponent = ({ file }: { file: MarimoFile }) => {+const MarimoFileComponent = ({+ file,+ openNewTab,+}: {+ file: MarimoFile;+ openNewTab: boolean;+}) => {// If path is a sessionId, then it has not been saved yet// We want to keep the sessionId in this caseconst isNewNotebook = isSessionId(file.path);@@ -383,10 +398,10 @@ const MarimoFileComponent = ({ file }: { file: MarimoFile }) => {return (<a- className="py-1.5 px-4 hover:bg-[var(--blue-2)] hover:text-primary transition-all duration-300 cursor-pointer group relative flex items-end gap-4 items-center"+ className="py-1.5 px-4 hover:bg-[var(--blue-2)] hover:text-primary transition-all duration-300 cursor-pointer group relative flex gap-4 items-center"key={file.path}href={href.toString()}- target={tabTarget(file.initializationId || file.path)}+ target={openNewTab ? tabTarget(file.initializationId || file.path) : ""}><div className="flex flex-col justify-between flex-1"><span className="flex items-center gap-2">@@ -409,10 +424,12 @@ const MarimoFileComponent = ({ file }: { file: MarimoFile }) => {<div><SessionShutdownButton filePath={file.path} /></div>- <ExternalLinkIcon- size={20}- className="group-hover:opacity-100 opacity-0 transition-all duration-300 text-primary"- />+ {openNewTab && (+ <ExternalLinkIcon+ size={20}+ className="group-hover:opacity-100 opacity-0 transition-all duration-300 text-primary"+ />+ )}</div>{!!file.lastModified && (<div className="text-xs text-muted-foreground opacity-80">diff --git a/frontend/src/utils/url.ts b/frontend/src/utils/url.tsindex 2a18d2ff03..93c3aa6c05 100644--- a/frontend/src/utils/url.ts+++ b/frontend/src/utils/url.ts@@ -8,13 +8,5 @@* If document.baseURI is set, it will be used as the base URL.*/export function asURL(path: string): URL {- if (path.startsWith("./")) {- return new URL(path, document.baseURI);- }-- if (path.startsWith("/")) {- return new URL(path, document.baseURI);- }-return new URL(path, document.baseURI);}