from reactpy import Reactive
import numpy as np
import pandas as pd
r = Reactive()
r.a = 2
r.b = r(lambda a: a*a)
before = r.b
with r.context(a=5):
during = r.b
after = r.b
before, during, after
(4, 25, 4)
r = Reactive()
r.c = r(lambda a,b: abs(a-b))
r.result = r(lambda a,b,c: a*b + c)
data = {}
for a, b in ((a, b) for a in range(10)
for b in range(10)):
with r.context(a=a, b=b):
data[(r.a, r.b)] = r.result
pd.Series(data).unstack()
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | |
---|---|---|---|---|---|---|---|---|---|---|
0 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
1 | 1 | 1 | 3 | 5 | 7 | 9 | 11 | 13 | 15 | 17 |
2 | 2 | 3 | 4 | 7 | 10 | 13 | 16 | 19 | 22 | 25 |
3 | 3 | 5 | 7 | 9 | 13 | 17 | 21 | 25 | 29 | 33 |
4 | 4 | 7 | 10 | 13 | 16 | 21 | 26 | 31 | 36 | 41 |
5 | 5 | 9 | 13 | 17 | 21 | 25 | 31 | 37 | 43 | 49 |
6 | 6 | 11 | 16 | 21 | 26 | 31 | 36 | 43 | 50 | 57 |
7 | 7 | 13 | 19 | 25 | 31 | 37 | 43 | 49 | 57 | 65 |
8 | 8 | 15 | 22 | 29 | 36 | 43 | 50 | 57 | 64 | 73 |
9 | 9 | 17 | 25 | 33 | 41 | 49 | 57 | 65 | 73 | 81 |