我正在尝试编写一个Bokeh应用程序,它可以动态地添加和删除选项卡面板,以响应服务器中发生的事件。它可以工作,但是在活动面板左侧添加或删除面板会导致活动面板发生更改,因为它对活动面板使用固定索引,而不是跟踪哪个面板对象处于活动状态。在
我可以通过首先检索活动面板,然后设置Tabs
对象上的active
属性将其强制返回当前活动面板,但这有两个问题:
有更好的方法吗?在
一些最小的代码(与bokeh server
一起使用)来演示基本问题(不包括我第二段中的解决方法):
from bokeh.models.widgets import Tabs, Panel, Paragraph, Button
from bokeh.layouts import column
from bokeh.io import curdoc
def callback():
if len(tabs.tabs) == 1:
tabs.tabs.insert(0, panels[0])
else:
del tabs.tabs[0]
panels = [
Panel(child=Paragraph(text='Panel 1'), title='Panel 1'),
Panel(child=Paragraph(text='Panel 2'), title='Panel 2')
]
tabs = Tabs(tabs=list(panels))
button = Button(label='Toggle')
button.on_click(callback)
curdoc().add_root(column(button, tabs))
工作示例,使用异步处理程序修复闪烁并提高分辨率。在
做了一系列改变:
serve()
入口点的应用程序。在代码如下:
相关问题 更多 >
编程相关推荐