Interacting with a tangle

IPython's interact can do some things that are awkward with straight widgets, such as generating plots. It will magically make built-in widgets from some simple settings objects.


In [12]:
import math
from IPython.html.widgets import interact
from IPython.display import display
from ipytangle import tangle

If you write your tangle first, you can link to its parts in an interact.

Because you can only have one tangle per page right now, see [Tangling up `interact`](./Tangling up interact.ipynb).

The fn function

The fn of x is fn_of_x.


In [13]:
trig_talk = tangle(
    fn=["sin", "cos", "tan"],
    x=1,
    fn_of_x=(0.0, lambda fn, x: getattr(math, fn)(x))
)
trig_talk

In [14]:
@interact
def interactor(t=trig_talk, y=1):
    print(t.fn_of_x + y)


1.8414709848078965

In [15]:
trig_talk.x = 2


1.9092974268256817