Skip to content

Instantly share code, notes, and snippets.

@david-macleod
Created September 9, 2019 20:41
Show Gist options
  • Save david-macleod/312404f28ef928df8e42312cdc9bbb00 to your computer and use it in GitHub Desktop.
Save david-macleod/312404f28ef928df8e42312cdc9bbb00 to your computer and use it in GitHub Desktop.
bokeh callbacks
from bokeh.models import CustomJS, ColumnDataSource
source = ColumnDataSource(data=dict(x=[0,0], y=[0, 80]))
# Javascript
callback = CustomJS(args=dict(source=source), code="""
var data = source.data;
var f = cb_obj.value
data['x'] = [f, f]
source.change.emit();
""")
model_obj.js_on_change('value', callback)
# Python
def callback(attrname, old, new):
source.data['x'] = [new, new]
model_obj.on_change('value', callback)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment