Easier way to avoid:RuntimeError: Models must be owned by only a single document, LinearAxis(id='7854', ...) is already in a doc

I have been working on a multi plot standalone dashboard on Jupyter notebook. I have 8 different jupyter notebook cells, each for one plot and a last one where I draw the layout. The problem is that every time I want to fix/change something, I get:

RuntimeError: Models must be owned by only a single document, LinearAxis(id=‘7854’, …) is already in a doc

I added “reset_output()”
To the beginning of the last cell (layout cell) but still have the same error.
Is there a way I can put this on debug mode or other way to avoid this error?

My solution so far is to re-run all 9 cells.

Hard to say anything specific without seeing the actual notebook. Some generic advice:

  • Don’t reuse variables
  • Don’t reuse Bokeh models between documents
  • Don’t create models at the top level of a cell. Instead, wrap them all in a function and call that function (similar to how bokeh serve does it internally)

The function solution was great. Thanks.