Published
Edited
Apr 2, 2019
1 fork
1 star
Insert cell
Insert cell
brython = require('brython').catch(() => window.brython)
//or brython = require('brython@3.7.1/brython.js').catch(() => window.brython)
Insert cell
ui = {
brython //? wait for
return html`
<script type="text/python">
# problem: after refreshing this cell (Shift+ENTER) - executing a Python script stops. Next brythonVer should be refreshed (or all page [F5]).

print('\\n PRINT: ok') # '\\n - inside html cell
print('\\n __BRYTHON__.__MAGIC__ ',__BRYTHON__.__MAGIC__,'\\n------\\n')
from browser import document #, alert() - doesn't work - unimportant.

def echo(ev):
s = document["zone"].value
document["echo2"].text = f'Hello - {s} !'
print(f'Hello {s} !')

btn = document["test"]; btn.unbind("click") # unbind, so re-evaluating this cell will be OK
btn.bind("click", echo)

</script>

<p>Your name is : <input id="zone" autocomplete="off" value="Test 0">
<button id="test">click !</button> <span id="echo2"><span>
`}
Insert cell
brythonVer = (ui, //run after the cell 'ui' is updated
(brython(1) || window.__BRYTHON__).__MAGIC__) //brython(1) is called here (!) - returns undefined (or Error - see console), so window.__BRYTHON__ is a result (as brython import test)
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more