How to refresh Bokeh Document

前端 未结 2 1787
梦如初夏
梦如初夏 2021-02-08 15:21

I would like to refresh a bokeh document so I can replace old plots with new ones. However, right now I just get the new plots appended to the document so the old ones don\'t go

2条回答
  •  情深已故
    2021-02-08 16:01

    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.

提交回复
热议问题