You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/how_to/interact/interact_abbreviations.md
+11-12
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,6 @@ To use `interact`, you need to define a function that you want to explore. Here
14
14
15
15
```{pyodide}
16
16
import panel as pn
17
-
from panel.interact import interact
18
17
from panel import widgets
19
18
20
19
pn.extension() # for notebook
@@ -26,7 +25,7 @@ def f(x):
26
25
When you pass this function to `interact` along with `x=10`, a slider is generated and bound to the function parameter, such that when you interact with the widget, the function is called.
27
26
28
27
```{pyodide}
29
-
interact(f, x=10)
28
+
pn.interact(f, x=10)
30
29
```
31
30
32
31
When you pass an integer-valued keyword argument of `10` (`x=10`) to `interact`, it generates an integer-valued slider control with a range of `[-10,+3*10]`. In this case, `10` is an *abbreviation* for an actual slider widget:
In fact, we can get the same result if we pass this `IntSlider` as the keyword argument for `x`:
39
38
40
39
```{pyodide}
41
-
interact(f, x=slider_widget)
40
+
pn.interact(f, x=slider_widget)
42
41
```
43
42
44
43
This examples clarifies how `interact` processes its keyword arguments:
@@ -64,35 +63,35 @@ If a 2-tuple of integers is passed `(min,max)`, an integer-valued slider is prod
64
63
65
64
66
65
```{pyodide}
67
-
interact(f, x=(0, 4))
66
+
pn.interact(f, x=(0, 4))
68
67
```
69
68
70
69
If a 3-tuple of integers is passed `(min,max,step)`, the step size can also be set.
71
70
72
71
73
72
```{pyodide}
74
-
interact(f, x=(0, 8, 2))
73
+
pn.interact(f, x=(0, 8, 2))
75
74
```
76
75
77
76
A float-valued slider is produced if the elements of the tuples are floats. Here the minimum is `0.0`, the maximum is `10.0` and step size is `0.1` (the default).
78
77
79
78
80
79
```{pyodide}
81
-
interact(f, x=(0.0, 10.0))
80
+
pn.interact(f, x=(0.0, 10.0))
82
81
```
83
82
84
83
The step size can be changed by passing a third element in the tuple.
85
84
86
85
87
86
```{pyodide}
88
-
interact(f, x=(0.0, 10.0, 0.01))
87
+
pn.interact(f, x=(0.0, 10.0, 0.01))
89
88
```
90
89
91
90
For both integer and float-valued sliders, you can pick the initial value of the widget by supplying a default keyword argument when you define the underlying Python function. Here we set the initial value of a float slider to `5.5`.
92
91
93
92
94
93
```{pyodide}
95
-
@interact(x=(0.0, 20.0, 0.5))
94
+
@pn.interact(x=(0.0, 20.0, 0.5))
96
95
def h(x=5.5):
97
96
return x
98
97
@@ -103,28 +102,28 @@ You can also set the initial value by passing a fourth element in the tuple.
103
102
104
103
105
104
```{pyodide}
106
-
interact(f, x=(0.0, 20.0, 0.5, 5.5))
105
+
pn.interact(f, x=(0.0, 20.0, 0.5, 5.5))
107
106
```
108
107
109
108
Use `None` as the third element to just set min, max, and value.
110
109
111
110
112
111
```{pyodide}
113
-
interact(f, x=(0.0, 20.0, None, 5.5))
112
+
pn.interact(f, x=(0.0, 20.0, None, 5.5))
114
113
```
115
114
116
115
Dropdown menus are constructed by passing a list of strings. In this case, the strings are both used as the names in the dropdown menu UI and passed to the underlying Python function.
117
116
118
117
119
118
```{pyodide}
120
-
interact(f, x=['apples', 'oranges'])
119
+
pn.interact(f, x=['apples', 'oranges'])
121
120
```
122
121
123
122
When working with numeric data ``interact`` will automatically add a discrete slider:
0 commit comments