In [1]:
from flexx import flx
In normal operation, one uses flx.launch() to fire up a browser (or desktop app) to run the JavaScript in. This is followed by flx.run() (or flx.start() for servers) to enter Flexx' main loop.
In the notebook, however, there already is a browser. To tell Flexx that we're in the notebook, use flx.init_notebook() at the start of your notebook. Since Flexx's event system is based on asyncio, we need to "activate" asyncio as well.
In [2]:
%gui asyncio
flx.init_notebook()
In [3]:
class MyComponent(flx.JsComponent):
foo = flx.StringProp('', settable=True)
@flx.reaction('foo')
def on_foo(self, *events):
if self.foo:
window.alert('foo is ' + self.foo, + len(events))
In [4]:
m = MyComponent()
In [5]:
m.set_foo('helo')
Out[5]:
Let's use an example model:
In [6]:
from flexxamples.testers.find_prime import PrimeFinder
p = PrimeFinder()
In [7]:
p.find_prime_py(2000)
Out[7]:
In [8]:
p.find_prime_js(2000) # Result is written to JS console, open F12 to see it
Out[8]:
In [ ]: