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
docs: improve docs for higher order elements (#342)
Akshay Agrawal799602e95dac
diff --git a/marimo/_plugins/ui/_impl/array.py b/marimo/_plugins/ui/_impl/array.pyindex b2cae9293e..dadd65c5dd 100644--- a/marimo/_plugins/ui/_impl/array.py+++ b/marimo/_plugins/ui/_impl/array.py@@ -23,6 +23,9 @@ class array(UIElement[Dict[str, JSONType], Sequence[object]]):- group together logically related UI elements- keep the number of global variables in your program small+ Access the values of the elements using the `value` attribute of the+ array.+The UI elements in the array are clones of the original elements:interacting with the array will _not_ update the original elements, andvice versa.@@ -35,6 +38,9 @@ class array(UIElement[Dict[str, JSONType], Sequence[object]]):array = mo.ui.array([mo.ui.slider(1, 10), mo.ui.text(), mo.ui.date()])```+ Get the values of the `slider`, `text`, and `date` elements via+ `array.value`:+```python# array.value returns a list with the values of the elementsarray.valuediff --git a/marimo/_plugins/ui/_impl/batch.py b/marimo/_plugins/ui/_impl/batch.pyindex 636e0d538d..d1c35c3a73 100644--- a/marimo/_plugins/ui/_impl/batch.py+++ b/marimo/_plugins/ui/_impl/batch.py@@ -65,8 +65,16 @@ class batch(_batch_base):represented by custom HTML or markdown. You can createa `batch` by calling the `batch()` method on `Html` objects.+ Get the value of the wrapped UI elements using the `value` attribute+ of the batch.+**Example.**+ In the below example, `user_info` is a UI Element whose output is markdown+ and whose value is a dict with keys `'name'` and '`birthday`'+ (and values equal to the values of their corresponding elements).++```python3user_info = mo.md('''@@ -76,9 +84,11 @@ class batch(_batch_base):).batch(name=mo.ui.text(), birthday=mo.ui.date())```- In this example, `user_info` is a UI Element whose output is markdown- and whose value is a dict with keys `'name'` and '`birthday`'- (and values equal to the values of their corresponding elements).+ To get the value of `name` and `birthday`, use:++ ```+ user_info.value+ ```You can also instantiate this class directly:diff --git a/marimo/_plugins/ui/_impl/dictionary.py b/marimo/_plugins/ui/_impl/dictionary.pyindex e5f26d107f..80f2809877 100644--- a/marimo/_plugins/ui/_impl/dictionary.py+++ b/marimo/_plugins/ui/_impl/dictionary.py@@ -16,10 +16,14 @@ class dictionary(_batch_base):A dictionary of UI elements.Use a dictionary to+- create a set of UI elements at runtime- group together logically related UI elements- keep the number of global variables in your program small+ Access the values of the elements using the `value` attribute of the+ dictionary.+The UI elements in the dictionary are clones of the original elements:interacting with the dictionary will _not_ update the originalelements, and vice versa.@@ -36,6 +40,9 @@ class dictionary(_batch_base):})```+ Get the values of the `slider`, `text`, and `date` elements via+ `d.value`:+```python# d.value returns a dict with keys "slider", "text", "date"d.value