Ally Alfie
Ally Alfie

Reputation: 141

How do I access a Bokeh (Python) variable with JS?

I'm making a dropdown which displays a certain plot depending on what is selected.

I've made my dropdown and begun my CustomJS callback function. At the moment, all I want to do is log whatever option is selected in the dropdown, but obviously I cant just console.log(myDropDownMenu.value);

myDropDownMenu = Select(options=['uniform', 'normal', 'lognormal'], value='uniform', title='Distribution')

callback = CustomJS(args=dict(source=source), code=
                    """
console.log("What should go in here?");
""")

myDropDownMenu.js_on_change('value', callback)

So if 'uniform' is selected in the dropdown, I expect 'uniform' to show up in my console... Any ideas?

Upvotes: 0

Views: 1298

Answers (2)

Tony
Tony

Reputation: 8287

By default the callback object cb_obj and callback data cb_data are available in each JS callback. Additionally, when using args callback attribute you can pass arbitrary number of additional objects as long as they are serializable (like source in your example). In your case this is the cb_object so you can access it's value property. You may consider using e.g. Google Chrome developers tools (ALT+CMD+I on Mac) to view and inspect those objects in JS console.

Upvotes: 1

Ally Alfie
Ally Alfie

Reputation: 141

Who would've known it was this easy?

console.log(this.value);

Rubber duck debugging at it's finest.

Upvotes: 1

Related Questions