0

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?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Tony. It's these little things I need to know that the docs I've seen don't seem to cover.
1

Who would've known it was this easy?

console.log(this.value);

Rubber duck debugging at it's finest.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.