1

How would I add a CustomJS callback for a Bokeh Panel? For example, say i want to change the text within a bokeh.model.Div based off the currently selected Panel in a Tab. My naive attempt is something like:

div = Div(text='Test Div', width=100, height=100)
panel = Panel(child=plot, title=plot.title)
callback = CustomJS(args=dict(div=div), code='div.text = "change successful!";')
panel.js_on_event(events.Tap, callback)

however this obviously doesn't work, So i'm wondering if anyone can correct this example?

1 Answer 1

2

I think the general approach is write a callback to register when the active panel changes. If you have your panels in a "Tabs" object, you can just write CustomJS (or a python based callback if your using a server). Simple example below.

div = Div(text="Pannel 1 is active")

p1text = Div(text="this is Panel 1")
p2text = Div(text="this is Panel 2")
p1 = Panel(child=p1text,title="Panel 1")
p2 = Panel(child=p2text,title="Panel 2")
tabs = Tabs(tabs=[p1,p2])
code = """
var active = tabs.active + 1;
div.text = "Panel "+active+" is active"
"""
callback = CustomJS(args={'tabs':tabs,'div':div}, code=code)
tabs.js_on_change('active',callback)
show(row(div,tabs))
Sign up to request clarification or add additional context in comments.

1 Comment

What about using tap to callback a tab in JS? Is that possible?

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.