Cleanly replace the curdoc() ?

Within a larger program, I am trying to replacing an entire figure within curdoc(). Yes, this is a workaround for the more sensical method of changing specific datasources. For now, I ask that we put that issue aside. Also, apologies that i don’t have a larger program to demonstrate the issue. If it’s necessary to resolve the issue, I can put the time in.

Here is the function demonstrating my current approach. Within changeTrial(), make_trial_figure() generates an entirely new bokeh Figure that I would like to replace the current figure. The resulting browser behavior is that the new document appears below the old document. I would like to remove the old document from the session.

Thanks!

def changeTrial():

    global fig, sourceList, trialSourceDict, session

    trialSourceDict = init_trial_datasources()
    force_update_sources()
    fig = make_trial_figure()

    # Add figure and widgets to a layout

<details class='elided'>
<summary title='Show trimmed content'>&#183;&#183;&#183;</summary>

###########################################################################
    from bokeh.layouts import layout
    layout = layout([[fig], [widgetBox]], sizing_mode='fixed')

    ###########################################################################
    # Add layout to current document
    from bokeh.io import curdoc, set_curdoc

    curdoc().clear()
    curdoc().add_root(layout)

Did you get any solution to this @Gabriel ?

···

On Saturday, July 9, 2016 at 2:03:42 AM UTC+5:30, Gabriel Diaz wrote:

Within a larger program, I am trying to replacing an entire figure within curdoc(). Yes, this is a workaround for the more sensical method of changing specific datasources. For now, I ask that we put that issue aside. Also, apologies that i don’t have a larger program to demonstrate the issue. If it’s necessary to resolve the issue, I can put the time in.

Here is the function demonstrating my current approach. Within changeTrial(), make_trial_figure() generates an entirely new bokeh Figure that I would like to replace the current figure. The resulting browser behavior is that the new document appears below the old document. I would like to remove the old document from the session.

Thanks!

def changeTrial():

    global fig, sourceList, trialSourceDict, session

    trialSourceDict = init_trial_datasources()
    force_update_sources()
    fig = make_trial_figure()

    # Add figure and widgets to a layout
    ###########################################################################
    from bokeh.layouts import layout
    layout = layout([[fig], [widgetBox]], sizing_mode='fixed')

    ###########################################################################
    # Add layout to current document
    from [bokeh.io](http://bokeh.io) import curdoc, set_curdoc

    curdoc().clear()
    curdoc().add_root(layout)

This might help :

Loading a saved document: https://stackoverflow.com/questions/46494811/how-to-replace-curdoc/46498077#46498077

Replacing models: https://stackoverflow.com/questions/46697867/replacing-figure-and-table-in-layout-when-using-global-columndatasource/46713283#46713283