Praveen Gupta Sanka
Praveen Gupta Sanka

Reputation: 631

Unable to trigger a selection event in bokeh

Can someone please tell me how to capture the option that is selected in the 'select' widget. I tried the following and expected that when I change the selection in drop down menu, it should print the newly selected option. But it's not happening.

from bokeh.models.widgets import Select
from bokeh.io import output_notebook, show, vform
from bokeh.models import CustomJS

output_notebook()
states=['VA','MD','SC']

select = Select(title="Select State:", value="VA", options=states)

show(vform(select))

def call(attr,old,new):
    print new

select.on_change('value',select,call)

Upvotes: 0

Views: 1269

Answers (1)

bigreddot
bigreddot

Reputation: 34568

You are calling on_change incorrectly. It takes: the name of the property to respond to, and the callback. You don't need to pass the object, because on_change is already a method on the object. You want:

select.on_change('value', call)

Also, I will suggest that is unequivocably a good idea and almost always more efficient to try to and find a working example to start from, and then experiment with modifying that to suit your needs. The authors of the library have worked hard to add many examples to the GitHub repo so that users can learn from them. Several of them show working Select widgets. Here is one in particular:

https://github.com/bokeh/bokeh/blob/master/examples/app/stocks/main.py

As an aside, I'm actually surprised the on_change call doesn't fall over with an error immediately, the way you have it. Please consider contributing by making a GitHub issue to suggest better validation.

Upvotes: 1

Related Questions