python - 无法清除 Bokeh 服务器中的文档

标签 python bokeh

这是我用来清除 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) )

最佳答案

尝试以这种方式完全清除文档可能会出现问题。当前最好的做法是使文档的顶层具有某种布局(例如 ),然后更新该布局的 child 。一般来说,从 Bokeh 0.12.3 开始,更新 东西比 替换 东西更可靠可能是正确的。

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

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

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

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

关于python - 无法清除 Bokeh 服务器中的文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40699936/

相关文章:

docker - 使用docker在Shinyproxy上运行bokeh

python - 如何配置 Bokeh 图以具有响应宽度和固定高度

python - KafkaRecord 不能转换为 [B

javascript - 防止第三方调用内部 POST 方法

python - Python 中的稀疏随机矩阵,其范围不同于 [0,1]

Python Bokeh 可能存在错误,仅显示最后一张图

python - 我怎样才能让这个Python脚本连续/一遍又一遍地运行

python - 如何使用 Numpy 在 Python 中 reshape 数组?

python - 无法在 Django 模板中嵌入 JSON Bokeh Plot

python - 面向对象 Bokeh 的多个问题 [已过时]