-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'Single Select' widget value #2618
Comments
Can you supply a code example. It really helps us narrow down the problem. |
Regarding callback, I realized my mistake where in I was calling a python function within the js snippet of the callback fn. Based on a value selected in one select, I need to do a lookup to get the options for the second select, if not a fn call, can i pass second CDS object in callback fn to be used for the lookup purpose? If I don't use callback and rely on '.value', it is not returning the selected value. Below are the two code examples. Thanks in advance --with callback ---
---- without callback ---
|
Yes. You can pass in as many source or other bokeh objects into the In one of my examples - I pass in 50 ColumnDataSources to the callback! |
Value of source CDS is updated correctly within the callback function but it is NOT reflecting outside the function as i mentioned previously. All examples I have seen have widget interaction data being used in plotting, here I am trying to use it in another widget instead. Is this okay? Please help! Here is the code.
|
.data is a dict/object that maps names to columns/arrays of data. You are setting it to a single number. |
I am sorry, I didn't get it. Which line of code you are referring to? If you are referring to javascript snippet, .data is being set to an Array. Alert in javascript confirms that. |
Sorry, traveling and only on my phone can't really say much more now. But .data should not be an array. It should be a dictionary (js object) with string keys and array values. |
Changed the code, now .data is a dict with string key and an array value. Still the problem persists... source object is correctly updated within the JS snippet but it is not reflecting outside. Kindly advise.
|
ping @mattpap @birdsarah |
Hi @mattpap , @birdsarah , Please help! Intention: To have multiple "single select" input widgets to be presented in an order such that options available in second widget onwards depends on the selection made in the previous widget. And finally present a data table based on these inputs. Problem: source object is getting updated correctly within JS of select1 but not reflecting outside, due to which select2 remains empty. ---- code --- from bokeh.io import vform output_notebook() cats=["one","two","three"] result={} result['one'] = ['a','b','c'] origin = ColumnDataSource(result) source = ColumnDataSource(data = dict(subcats=[])) callback = Callback(args=dict(source=source), code=""" callback.args["origin"] = origin select1 = Select(title="Cat1", value=cats[0], options=cats, callback=callback) select2 = Select(title="Cat2", value="", options=source.data['subcats']) layout = vform(select1, select2) show(layout) |
I don't think this is possible. I don't think the options for a Select widget are "powered" by a data source. All you are doing is setting the options to a list (source.data['subcats'] is a list of values) you are not making a link between the Select widget and a data source. |
@softengash you should change the Select widget
on your callback if you define s2 like:
|
I did as suggested and it finally worked!! Thank you :) @fpliger So how would I get the selected value of select1 outside the JS code to do a data lookup in python? 'select1.value' in python returns None!! Kindly advise. |
Have you tried |
To get the value back from a Bokeh widget to python code you will have to use a Bokeh Server. If you just need widgets in the Jupyter/IPython notebook, you might looks at some of the examples that use IPython interactors (look under |
Thank you @bryevdv |
@softengash do you have a final example of this working? I still can't seem to put it all together. Thanks! |
callback = Callback(args=dict(source=source), code=""" s1 = Select(title="Select1", value='initial value in your dropdown', options='list of values of your dropdown', callback=callback) |
Hi,
I am working on 0.9.2 version. My main intention is to have multiple "single select" input widgets to be presented in an order such that options available in second widget onwards depends on the selection made in the previous widget.
I tried callback option and update a ColumnDataSource object and make its data as options for the other select widget. It doesn't seem to reflect. Second select always remain blank, as if it never gets the data.
Then I tried to get the selected value of the first widget by using '.value'. But it gives me the initial value of the widget only irrespective whatever I select from the options.
Not sure if it is an issue or am I missing anything. Kindly advise.
Thanks
Ashish
The text was updated successfully, but these errors were encountered: