无法清除散景服务器中的文档

Unable to clear document in bokeh server

这是我用来清除 Bokeh 服务器中高级图表的示例代码。我想在通过点击按钮清除旧情节后添加一个新的高级情节,但我无法清除旧情节。 Sample screenshot

from bokeh.charts import  Bar
from bokeh.layouts import column
from bokeh.models.widgets import Button
from bokeh.plotting import  curdoc

from bokeh.sampledata.autompg import autompg as df

button = Button(label="Clear")

def clear():
    curdoc().clear()

p = Bar(df, 'cyl', values='mpg', 
        title="Total MPG by cyl")

button.on_click(clear)
curdoc().add_root(column(button,p) )

尝试以这种方式完全清除文档可能会出现问题。当前最好的做法是使文档的顶层成为某种布局(例如 rowcolumn),然后 update 该布局的子级。一般来说,对于 Bokeh 0.12.3 来说 updatereplace 更可靠.

您可以在交叉过滤器示例中看到这样的示例:

https://github.com/bokeh/bokeh/blob/master/examples/app/crossfilter/main.py#L72

它在哪里使用这样的代码:

def update(attr, old, new):
    layout.children[1] = create_figure()