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
doc: fix prior incorrect interpretation of marimo dict (#2731)
eugenea2b886670b24
diff --git a/examples/ui/arrays_and_dicts.py b/examples/ui/arrays_and_dicts.pyindex 09b045ed40..6389554c66 100644--- a/examples/ui/arrays_and_dicts.py+++ b/examples/ui/arrays_and_dicts.py@@ -78,17 +78,13 @@ def __(array, dictionary, mo):return[email protected](hide_code=True)def __(mo):mo.md(r"""- Fundamental difference between marimo dict and standard python dict.-- The UI elements in marimo dict are clones of the original: interacting with the marimo dictionary will not update the original elements, and vice versa.+ Key difference between marimo dict and standard python dict:- This allows you to reuse multiple UI components (e.g., sliders, text inputs, or date pickers) independently, ensuring they don’t interfere with each other when managed through marimo dict.-- However, if you use a regular python dict, all references remain synchronized, and changes to one element propagate across all linked instances.+ The main reason to use `mo.ui.dictionary` is for reactive execution — when you interact with an element in a `mo.ui.dictionary`, all cells that reference the `mo.ui.dictionary` run automatically, just like all other ui elements. When you use a regular dictionary, you don't get this reactivity.""")return@@ -127,6 +123,26 @@ def __(create, mo):return date, mo_d, py_d, slider, text[email protected](hide_code=True)+def __(mo, mo_d, py_d):+ mo_d_ref = {k: mo_d[k].value for k in mo_d.value.keys()}+ py_d_ref = {k: py_d[k].value for k in py_d.keys()}+ mo.hstack(+ [+ mo.vstack(["reference of marimo dict", mo_d_ref]),+ mo.vstack(["reference of python dict", py_d_ref]),+ ],+ justify="space-around",+ )+ return mo_d_ref, py_d_ref++[email protected](hide_code=True)+def __(mo):+ mo.md(r"""Notice that when you interact with the UI elements in the marimo dict, the reference of marimo dict updates automatically. However, when you interact with the elements in the python dict, you need to manually re-run the cell to see the updated values.""")+ return++@app.celldef __():import marimo as modiff --git a/marimo/_plugins/ui/_impl/dictionary.py b/marimo/_plugins/ui/_impl/dictionary.pyindex 5c5aeb8e45..ddf7ae1a03 100644--- a/marimo/_plugins/ui/_impl/dictionary.py+++ b/marimo/_plugins/ui/_impl/dictionary.py@@ -34,13 +34,10 @@ class dictionary(_batch_base):elements: interacting with the dictionary will _not_ update the originalelements, and vice versa.- This allows you to reuse multiple UI components (e.g., sliders, text- inputs, or date pickers) independently, ensuring they don’t interfere with- each other when managed through `mo.ui.dictionary`.-- However, if you use a regular Python dictionary, all references remain- synchronized, and changes to one element propagate across all linked- instances.+ The main reason to use mo.ui.dictionary is for reactive execution — when you+ interact with an element in a mo.ui.dictionary, all cells that reference the+ mo.ui.dictionary run automatically, just like all other ui elements. When you+ use a regular dictionary, you don't get this reactivity.**Examples.**