-
Notifications
You must be signed in to change notification settings - Fork 348
/
Copy pathbatch_and_form.py
100 lines (72 loc) · 1.71 KB
/
batch_and_form.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# /// script
# requires-python = ">=3.9"
# dependencies = [
# "marimo",
# ]
# ///
import marimo
__generated_with = "0.10.6"
app = marimo.App()
@app.cell
def _():
import marimo as mo
return (mo,)
@app.cell
def _(mo):
mo.md("""# Batch and Form""")
return
@app.cell
def _(mo):
mo.md(
"""
Make custom UI elements using `batch()`, and turn any UI element
into a form with `form()`.
"""
)
return
@app.cell
def _(mo, reset):
reset
variables = (
mo.md(
"""
Choose your variable values
{x}
{y}
"""
)
.batch(
x=mo.ui.slider(start=1, stop=10, step=1, label="$x =$"),
y=mo.ui.slider(start=1, stop=10, step=1, label="$y =$"),
)
.form(show_clear_button=True, bordered=False)
)
variables
return (variables,)
@app.cell
def _(mo, reset, submitted_values, variables):
if variables.value is not None:
submitted_values["x"].add(variables.value["x"])
submitted_values["y"].add(variables.value["y"])
x = variables.value["x"] if variables.value else "\ldots"
y = variables.value["y"] if variables.value else "\ldots"
mo.md(
f"""
At the moment,
$x = {x}$ and $y = {y}$
All values ever assumed by $x$ and $y$ are
{mo.hstack([mo.tree(submitted_values), reset], align="center", gap=4)}
"""
).callout()
return x, y
@app.cell
def _(reset):
reset
submitted_values = {"x": set(), "y": set()}
return (submitted_values,)
@app.cell
def _(mo):
reset = mo.ui.button(label="reset history")
return (reset,)
if __name__ == "__main__":
app.run()