Bokeh’s Python callbacks are called when certain attributes on a Bokeh
Model are changed. The function signature of event
handlers is determined by how they are attached to widgets (whether by
.on_event, for example).
on_change callback triggers#
All widgets, for example, have an
.on_change method that takes an attribute name and one or more event
handlers as parameters. These handlers are expected to have the function
(attr, old, new), where
attr refers to the changed
attribute’s name, and
new refer to the previous and updated
values of the attribute.
def my_text_input_handler(attr, old, new): print("Previous label: " + old) print("Updated label: " + new) text_input = TextInput(value="default", title="Label:") text_input.on_change("value", my_text_input_handler)
on_event callback triggers#
Additionally, some widgets, including the
.on_event method that takes an event handler as its only parameter. For
Button, this handler is called without parameters. For the other
.on_event, the handler is passed the new attribute value.
def my_radio_handler(new): print('Radio button option ' + str(new) + ' selected.') radio_group = RadioGroup(labels=["Option 1", "Option 2", "Option 3"], active=0) radio_group.on_event('button_click', my_radio_handler)