Interacting with a tangleIPython'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.
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)
In [15]:
trig_talk.x = 2