#!/usr/bin/env python # coding: utf-8 # 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. # In[1]: import pandas as pd from io import BytesIO # In[2]: from reactpy import Reactive, Interact, Plot, FileData, Output O = Output get_ipython().run_line_magic('matplotlib', 'widget') # In[3]: r = reactive = Reactive(lazy_eval=False) r.update(get_ipython().user_ns) get_ipython().user_ns = r # In[4]: a = 2 b = r(lambda a: a+3) o = O(lambda a,b: (a, b)) o # In[5]: a = 3 # In[6]: c = Interact('c', (-100, 100, 1)) d = Interact('d', (-100, 100, 1)) oo = O(lambda c,d: (c,d)) oo # In[7]: p = Plot(lambda ax, c, d: ax.plot([(x+c)*(x+d)*x for x in range(-100, 100)])) # In[8]: alist = [0, 2, 5, 6, 8, 9, 11, 23, 21, 32] item = 6 alist, item # In[9]: first = 0 last = alist.__len__()-1 found = False mon = O(lambda first, last, found: (first, last, found)) mon # In[10]: 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 # In[12]: x = 2 y = 3 @reactive def z(x, y): return x+y z # In[13]: x = 5 # In[14]: z # In[16]: @O def o(z): return z o # In[18]: x = 39