Skip to content

Commit

Permalink
Lazily work-around interact docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro committed Aug 30, 2024
1 parent 911c044 commit f0dd283
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 394 deletions.
23 changes: 11 additions & 12 deletions doc/how_to/interact/interact_abbreviations.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ To use `interact`, you need to define a function that you want to explore. Here

```{pyodide}
import panel as pn
from panel.interact import interact
from panel import widgets
pn.extension() # for notebook
Expand All @@ -26,7 +25,7 @@ def f(x):
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.

```{pyodide}
interact(f, x=10)
pn.interact(f, x=10)
```

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:
Expand All @@ -38,7 +37,7 @@ slider_widget = widgets.IntSlider(start=-10,end=30,step=1,value=10)
In fact, we can get the same result if we pass this `IntSlider` as the keyword argument for `x`:

```{pyodide}
interact(f, x=slider_widget)
pn.interact(f, x=slider_widget)
```

This examples clarifies how `interact` processes its keyword arguments:
Expand All @@ -64,35 +63,35 @@ If a 2-tuple of integers is passed `(min,max)`, an integer-valued slider is prod


```{pyodide}
interact(f, x=(0, 4))
pn.interact(f, x=(0, 4))
```

If a 3-tuple of integers is passed `(min,max,step)`, the step size can also be set.


```{pyodide}
interact(f, x=(0, 8, 2))
pn.interact(f, x=(0, 8, 2))
```

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).


```{pyodide}
interact(f, x=(0.0, 10.0))
pn.interact(f, x=(0.0, 10.0))
```

The step size can be changed by passing a third element in the tuple.


```{pyodide}
interact(f, x=(0.0, 10.0, 0.01))
pn.interact(f, x=(0.0, 10.0, 0.01))
```

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`.


```{pyodide}
@interact(x=(0.0, 20.0, 0.5))
@pn.interact(x=(0.0, 20.0, 0.5))
def h(x=5.5):
return x
Expand All @@ -103,28 +102,28 @@ You can also set the initial value by passing a fourth element in the tuple.


```{pyodide}
interact(f, x=(0.0, 20.0, 0.5, 5.5))
pn.interact(f, x=(0.0, 20.0, 0.5, 5.5))
```

Use `None` as the third element to just set min, max, and value.


```{pyodide}
interact(f, x=(0.0, 20.0, None, 5.5))
pn.interact(f, x=(0.0, 20.0, None, 5.5))
```

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.


```{pyodide}
interact(f, x=['apples', 'oranges'])
pn.interact(f, x=['apples', 'oranges'])
```

When working with numeric data ``interact`` will automatically add a discrete slider:


```{pyodide}
interact(f, x=dict([('one', 10), ('two', 20)]))
pn.interact(f, x=dict([('one', 10), ('two', 20)]))
```

## Related Resources
4 changes: 2 additions & 2 deletions doc/how_to/interact/interact_fix_values.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ First, let's declare a simple function.

```{pyodide}
import panel as pn
from panel.interact import fixed
from panel._interact import fixed
pn.extension() # for notebook
def f(x, y):
return x, y
```

Now, call `interact` using the `panel.interact.fixed` function to fix one of the values:
Now, call `interact` using the `panel._interact.fixed` function to fix one of the values:

```{pyodide}
pn.interact(f, x=1, y=fixed(10))
Expand Down
4 changes: 2 additions & 2 deletions panel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
from . import (
layout, links, pane, param, pipeline, template, viewable, widgets,
)
from .interact import interact
from ._interact import interact
from .io import serve, state
from .io.cache import cache
from .io.notebook import ( # noqa: F401
Expand Down Expand Up @@ -102,7 +102,7 @@
"config": "panel.config:config",
"custom": "panel.custom",
"indicators": "panel.widgets:indicators",
"interact": "panel.interact:interact",
"interact": "panel._interact:interact",
"ipywidget": "panel.io.notebook:ipywidget",
"layout": "panel.layout",
"links": "panel.links",
Expand Down
Loading

0 comments on commit f0dd283

Please sign in to comment.