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?

asdf
  • 836
  • 1
  • 12
  • 29

1 Answers1

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))
Anthonydouc
  • 3,334
  • 1
  • 16
  • 29