Skip to content

Instantly share code, notes, and snippets.

@axil
Last active August 26, 2022 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save axil/fc1132d49e8b72e2e508051e44155fad to your computer and use it in GitHub Desktop.
Save axil/fc1132d49e8b72e2e508051e44155fad to your computer and use it in GitHub Desktop.
roundtrip
import bokeh.models as bm
from bokeh.layouts import row
from bokeh.plotting import show
data = bm.TextInput(width=100)
go = bm.Button(label='Go', width=50)
result = bm.TextInput(width=100)
callback = bm.CustomJS(args={'data': data, 'result': result}, code="""
var g = window.pyodide.globals;
g.set('data', data.value);
window.pyodide.runPython(`
squared = str(int(data)**2);
`);
result.value = g.get('squared');
result.change.emit();
""")
go.js_on_click(callback)
show(row(data, go, result))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment