2016-11-20 16 views
1

以下是我用於清除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)) 

回答

1

嘗試以這種方式完全清除文檔可能存在問題。目前最好的做法是將文檔的頂層設置爲某種佈局(例如,rowcolumn),然後再將update設置爲該佈局的子級。一般來說,至於散景0.12.3它可能是真實的說,它是更可靠的更新的東西,比取代東西。

你可以看到在crossfilter例如這樣一個例子:

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

凡使用這樣的代碼:

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