This is highly experimental, but we could even imagine make the notebook reactive. This can be achieved by reaching into the ipython internals and overwriting the namespace. This has bugs.
import pandas as pd
from io import BytesIO
from reactpy import Reactive, Interact, Plot, FileData, Output
O = Output
%matplotlib widget
r = reactive = Reactive(lazy_eval=False)
r.update(get_ipython().user_ns)
get_ipython().user_ns = r
a = 2
b = r(lambda a: a+3)
o = O(lambda a,b: (a, b))
o
Output(outputs=({'output_type': 'stream', 'name': 'stdout', 'text': '(2, 5)'},))
a = 3
c = Interact('c', (-100, 100, 1))
d = Interact('d', (-100, 100, 1))
oo = O(lambda c,d: (c,d))
oo
interactive(children=(IntSlider(value=0, description='value', min=-100), Output()), _dom_classes=('widget-inte…
interactive(children=(IntSlider(value=0, description='value', min=-100), Output()), _dom_classes=('widget-inte…
Output(outputs=({'output_type': 'stream', 'name': 'stdout', 'text': '(0, 0)'},))
p = Plot(lambda ax, c, d: ax.plot([(x+c)*(x+d)*x for x in range(-100, 100)]))
Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …
alist = [0, 2, 5, 6, 8, 9, 11, 23, 21, 32]
item = 6
alist, item
([0, 2, 5, 6, 8, 9, 11, 23, 21, 32], 6)
first = 0
last = alist.__len__()-1
found = False
mon = O(lambda first, last, found: (first, last, found))
mon
Output(outputs=({'output_type': 'stream', 'name': 'stdout', 'text': '(0, 9, False)'},))
while first<=last and not found:
midpoint = (first + last)//2
if alist[midpoint] == item:
found = True
else:
if item < alist[midpoint]:
last = midpoint-1
else:
first = midpoint+1
x = 2
y = 3
@reactive
def z(x, y):
return x+y
z
5
x = 5
z
8
@O
def o(z):
return z
o
Output(outputs=({'output_type': 'stream', 'name': 'stdout', 'text': '8'},))
x = 39