How to refresh Bokeh Document

旧街凉风 提交于 2019-12-03 06:24:48

The best way to accomplish something like this is to have a top level layout of some kind (e.g. row or column) that has the content you want to replace inside it. Then when you want to replace things, keep the layout container, but change the value of its children property:

from bokeh.plotting import curdoc, figure
from bokeh.layouts import row

doc = curdoc()

p1 = figure(width=1500, height=230, active_scroll="wheel_zoom")

layout = row(p1)
doc.add_root(layout)

p2 = figure(width=1500, height=500, active_scroll="wheel_zoom")

layout.children[0] = p2

You can see a similar technique in the Crossfilter example.

Just in case anyone is struggling on how to set the children for layouts when there are multiple elements (say, widgets, more figures, rows etc), you can do so by wrapping the elements in a layout and assigning the children property directly:

p2 = figure(width=1500, height=500, active_scroll="wheel_zoom")
p3 = figure(width=1500, height=500, active_scroll="wheel_zoom")
new_layout = row(p2, p3)
layout.children = new_layout.children
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!