面板/选项卡上的散景python回调

时间:2019-05-06 11:19:18

标签: python callback tabs panel bokeh

使用python中的bokeh模块,当有人选择其他面板时,我想添加服务器回调。这样的事情(不幸的是,它不起作用):

from bokeh.layouts import widgetbox
from bokeh.models.widgets import Div, Tabs, Panel
from bokeh.plotting import curdoc

label1 = Div(text='Tab 1')
label2 = Div(text='Tab 2')
panel1 = Panel(child=widgetbox(label1), title='Tab 1')
panel2 = Panel(child=widgetbox(label2), title='Tab 2')
tabs = Tabs(tabs=[panel1, panel2])

def panelActive():
    print("the active panel is "+str(tabs.active))
tabs.callback=panelActive()

curdoc().add_root(tabs)

编辑:这是在bokeh 0.13.0中

1 个答案:

答案 0 :(得分:1)

您应该尝试(Bokeh v1.1.0):

from bokeh.layouts import widgetbox
from bokeh.models import Div, Tabs, Panel
from bokeh.plotting import curdoc

label1 = Div(text = 'Tab 1')
label2 = Div(text = 'Tab 2')
panel1 = Panel(child = widgetbox(label1), title = 'Tab 1')
panel2 = Panel(child = widgetbox(label2), title = 'Tab 2')
tabs = Tabs(tabs = [panel1, panel2])

def panelActive(attr, old, new):
    print("the active panel is " + str(tabs.active))

tabs.on_change('active', panelActive)

curdoc().add_root(tabs)