Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470import marimo__generated_with = "0.9.2"app = marimo.App()@app.celldef __():import marimo as momo.md("# Welcome to marimo! 🌊🍃")return (mo,)@app.celldef __(mo):slider = mo.ui.slider(1, 22)return (slider,)@app.celldef __(mo, slider):mo.md(f"""marimo is a **reactive** Python notebook.This means that unlike traditional notebooks, marimo notebooks **runautomatically** when you modify them orinteract with UI elements, like this slider: {slider}.{"##" + "🍃" * slider.value}""")return@app.cell(hide_code=True)def __(mo):mo.accordion({"Tip: disabling automatic execution": mo.md(rf"""marimo lets you disable automatic execution: just go into thenotebook settings and set"Runtime > On Cell Change" to "lazy".When the runtime is lazy, after running a cell, marimo marks itsdescendants as stale instead of automatically running them. Thelazy runtime puts you in control over when cells are run, whilestill giving guarantees about the notebook state.""")})return@app.cell(hide_code=True)def __(mo):mo.md("""Tip: This is a tutorial notebook. You can create your own notebooksby entering `marimo edit` at the command line.""").callout()return@app.cell(hide_code=True)def __(mo):mo.md("""## 1. Reactive executionA marimo notebook is made up of small blocks of Python code calledcells.marimo reads your cells and models the dependencies among them: whenevera cell that defines a global variable is run, marimo**automatically runs** all cells that reference that variable.Reactivity keeps your program state and outputs in sync with your code,making for a dynamic programming environment that prevents bugs before theyhappen.""")return@app.cell(hide_code=True)def __(changed, mo):(mo.md(f"""**✨ Nice!** The value of `changed` is now {changed}.When you updated the value of the variable `changed`, marimo**reacted** by running this cell automatically, because this cellreferences the global variable `changed`.Reactivity ensures that your notebook state is alwaysconsistent, which is crucial for doing good science; it's also whatenables marimo notebooks to double as tools and apps.""")if changedelse mo.md("""**🌊 See it in action.** In the next cell, change the value of thevariable `changed` to `True`, then click the run button."""))return@app.celldef __():changed = Falsereturn (changed,)@app.cell(hide_code=True)def __(mo):mo.accordion({"Tip: execution order": ("""The order of cells on the page has no bearing onthe order in which cells are executed: marimo knows that a cellreading a variable must run after the cell that defines it. Thisfrees you to organize your code in the way that makes the mostsense for you.""")})return@app.cell(hide_code=True)def __(mo):mo.md("""**Global names must be unique.** To enable reactivity, marimo imposes aconstraint on how names appear in cells: no two cells may define the samevariable.""")return@app.cell(hide_code=True)def __(mo):mo.accordion({"Tip: encapsulation": ("""By encapsulating logic in functions, classes, or Python modules,you can minimize the number of global variables in your notebook.""")})return@app.cell(hide_code=True)def __(mo):mo.accordion({"Tip: private variables": ("""Variables prefixed with an underscore are "private" to a cell, sothey can be defined by multiple cells.""")})return@app.cell(hide_code=True)def __(mo):mo.md("""## 2. UI elementsCells can output interactive UI elements. Interacting with a UIelement **automatically triggers notebook execution**: whenyou interact with a UI element, its value is sent back to Python, andevery cell that references that element is re-run.marimo provides a library of UI elements to choose from under`marimo.ui`.""")return@app.celldef __(mo):mo.md("""**🌊 Some UI elements.** Try interacting with the below elements.""")return@app.celldef __(mo):icon = mo.ui.dropdown(["🍃", "🌊", "✨"], value="🍃")return (icon,)@app.celldef __(icon, mo):repetitions = mo.ui.slider(1, 16, label=f"number of {icon.value}: ")return (repetitions,)@app.celldef __(icon, repetitions):icon, repetitionsreturn@app.celldef __(icon, mo, repetitions):mo.md("# " + icon.value * repetitions.value)return@app.cell(hide_code=True)def __(mo):mo.md("""## 3. marimo is just Pythonmarimo cells parse Python (and only Python), and marimo notebooks arestored as pure Python files — outputs are _not_ included. There's nomagical syntax.The Python files generated by marimo are:- easily versioned with git, yielding minimal diffs- legible for both humans and machines- formattable using your tool of choice,- usable as Python scripts, with UI elements taking their defaultvalues, and- importable by other modules (more on that in the future).""")return@app.cell(hide_code=True)def __(mo):mo.md("""## 4. Running notebooks as appsmarimo notebooks can double as apps. Click the app window icon in thebottom-right to see this notebook in "app view."Serve a notebook as an app with `marimo run` at the command-line.Of course, you can use marimo just to level-up yournotebooking, without ever making apps.""")return@app.cell(hide_code=True)def __(mo):mo.md("""## 5. The `marimo` command-line tool**Creating and editing notebooks.** Use```marimo edit```in a terminal to start the marimo notebook server. From hereyou can create a new notebook or edit existing ones.**Running as apps.** Use```marimo run notebook.py```to start a webserver that serves your notebook as an app in read-only mode,with code cells hidden.**Convert a Jupyter notebook.** Convert a Jupyter notebook to a marimonotebook using `marimo convert`:```marimo convert your_notebook.ipynb > your_app.py```**Tutorials.** marimo comes packaged with tutorials:- `dataflow`: more on marimo's automatic execution- `ui`: how to use UI elements- `markdown`: how to write markdown, with interpolated values andLaTeX- `plots`: how plotting works in marimo- `sql`: how to use SQL- `layout`: layout elements in marimo- `fileformat`: how marimo's file format works- `markdown-format`: for using `.md` files in marimo- `for-jupyter-users`: if you are coming from JupyterStart a tutorial with `marimo tutorial`; for example,```marimo tutorial dataflow```In addition to tutorials, we have examples in our[our GitHub repo](https://www.github.com/marimo-team/marimo/tree/main/examples).""")return@app.cell(hide_code=True)def __(mo):mo.md("""## 6. The marimo editorHere are some tips to help you get started with the marimo editor.""")return@app.celldef __(mo, tips):mo.accordion(tips)return@app.cell(hide_code=True)def __(mo):mo.md("""## Finally, a fun fact""")return@app.cell(hide_code=True)def __(mo):mo.md("""The name "marimo" is a reference to a type of algae that, underthe right conditions, clumps together to form a small spherecalled a "marimo moss ball". Made of just strands of algae, thesebeloved assemblages are greater than the sum of their parts.""")return@app.cell(hide_code=True)def __():tips = {"Saving": ("""**Saving**- _Name_ your app using the box at the top of the screen, orwith `Ctrl/Cmd+s`. You can also create a named app at thecommand line, e.g., `marimo edit app_name.py`.- _Save_ by clicking the save icon on the bottom right, or byinputting `Ctrl/Cmd+s`. By default marimo is configuredto autosave."""),"Running": ("""1. _Run a cell_ by clicking the play ( ▷ ) button on the topright of a cell, or by inputting `Ctrl/Cmd+Enter`.2. _Run a stale cell_ by clicking the yellow run button on theright of the cell, or by inputting `Ctrl/Cmd+Enter`. A cell isstale when its code has been modified but not run.3. _Run all stale cells_ by clicking the play ( ▷ ) button onthe bottom right of the screen, or input `Ctrl/Cmd+Shift+r`."""),"Console Output": ("""Console output (e.g., `print()` statements) is shown below acell."""),"Creating, Moving, and Deleting Cells": ("""1. _Create_ a new cell above or below a given one by clickingthe plus button to the left of the cell, which appears onmouse hover.2. _Move_ a cell up or down by dragging on the handle to theright of the cell, which appears on mouse hover.3. _Delete_ a cell by clicking the trash bin icon. Bring itback by clicking the undo button on the bottom right of thescreen, or with `Ctrl/Cmd+Shift+z`."""),"Disabling Automatic Execution": ("""Via the notebook settings (gear icon) or footer panel, youcan disable automatic execution. This is helpful whenworking with expensive notebooks or notebooks that haveside-effects like database transactions."""),"Disabling Cells": ("""You can disable a cell via the cell context menu.marimo will never run a disabled cell or any cells that depend on it.This can help prevent accidental execution of expensive computationswhen editing a notebook."""),"Code Folding": ("""You can collapse or fold the code in a cell by clicking the arrowicons in the line number column to the left, or by using keyboardshortcuts.Use the command palette (`Ctrl/Cmd+k`) or a keyboard shortcut toquickly fold or unfold all cells."""),"Code Formatting": ("""If you have [ruff](https://github.com/astral-sh/ruff) installed,you can format a cell with the keyboard shortcut `Ctrl/Cmd+b`."""),"Command Palette": ("""Use `Ctrl/Cmd+k` to open the command palette."""),"Keyboard Shortcuts": ("""Open the notebook menu (top-right) or input `Ctrl/Cmd+Shift+h` toview a list of all keyboard shortcuts."""),"Configuration": ("""Configure the editor by clicking the gears icon near the top-rightof the screen."""),}return (tips,)if __name__ == "__main__":app.run()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657# /// script# requires-python = ">=3.10"# dependencies = [# "marimo",# "gqlalchemy",# "plotly",# ]# ///import marimo__generated_with = "0.9.0"app = marimo.App()@app.celldef _():import marimo as moreturn (mo,)@app.celldef _(mo):mo.md("# 🦀 VerdantClaw-Secure")mo.md("""**Status:** OnlineThis is your custom Marimo notebook!---## Try the slider:""")number = mo.ui.slider(1, 10, value=5, label="Pick a number")return mo.vstack([number,mo.md(f"You picked: **{number.value}**")])@app.celldef _(mo):mo.md("""---## Add More CellsClick the **+** button (top right) to add new cells!""")returnif __name__ == "__main__":app.run()
app.py+39-452