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.

1.0 KB
Raw Blame
# /// script
# requires-python = ">=3.12"
# dependencies = [
#     "polars==1.39.3",
#     "vega-datasets==0.9.0",
# ]
# ///

import marimo

__generated_with = "0.25.2"
app = marimo.App(width="medium")


@app.cell
def _():
    import marimo as mo

    return (mo,)


@app.cell
def _():
    import os

    return (os,)


@app.cell
def _():
    DATA_FILE = "data.csv"
    return (DATA_FILE,)


@app.cell
def _(DATA_FILE: str, mo, os):
    import polars as pl

    if not os.path.exists(DATA_FILE):
        from vega_datasets import data

        data.cars().to_csv(DATA_FILE)

    editor = mo.ui.data_editor(pl.read_csv(DATA_FILE)).form(bordered=False)
    editor
    return (editor,)


@app.cell(hide_code=True)
def _(mo):
    mo.md("""
    The following cell writes the updated dataframe to disk when the submit button is clicked.
    """)


@app.cell
def _(DATA_FILE: str, editor, mo):
    mo.stop(editor.value is None, mo.md("Submit your changes."))

    editor.value.write_csv(DATA_FILE)


if __name__ == "__main__":
    app.run()