0

when trying to enter two datasource this error popped up. RuntimeError: Models must be owned by only a single document, StringFormatter(id='1266', ...) is already in a doc

df_2 = pd.DataFrame({
    'Fields': x ,
    'C_Info': values
})

src_1 = ColumnDataSource(df_2)

cols = [
    TableColumn(field='Fields', title='Portfolio'),
    TableColumn(field='C_Info', title='CapInfo')
]

myTable = DataTable(source=src_1, columns=cols)

src_3 = ColumnDataSource(df2)

cols_1 = [
    TableColumn(field='variable', title='Earnings Component'),
    TableColumn(field='values', title='Amount'),
    TableColumn(field='PercentageTotalEarning', title='Percentage Total Earning'),
]

myTable2 = DataTable(source=src_3, columns=cols_1)

show(column(myTable,myTable2))
  • 1
    Are you using a Jupyter Notebook? This looks like an error which comes when you try to show a Bokeh Model twice. Did you run different cells with `show()`? – mosc9575 Apr 18 '22 at 12:21
  • yes used show multiple times in the doc and it occurs only in jupyter notebook? – Prem mumma reddy Apr 22 '22 at 06:49
  • 1
    I know this from notebooks and can't say anything about scritps. Guess there this problem doesn't exist because the saving space is cleared immediately. – mosc9575 Apr 22 '22 at 06:51

1 Answers1

0

This error occurs when using bokeh.plotting.save and bokeh.plotting.show in the same cell of a python notebook.

Solution

import bokeh
import bokeh.io
bokeh.io.output_notebook()
import bokeh.plotting
from bokeh.models import HoverTool
from IPython.display import IFrame

Now create your figure as usual, calling bokeh.plotting.figure():

p = bokeh.plotting.figure(your figure as usual with plot_width and plot_height)

Now save your figure but don't show it using bokeh:

bokeh.plotting.save(p, filename="your path/name.html")

Now show your figure using IFrame:

IFrame(src='your path/name.html', width=1000, height=500)

Please note, width and height in IFrame should be set slightly larger than your figure dimension that you have set in plot_width and plot_height

Now you have both the saving and the displaying in the same cell.

Riman
  • 21
  • 1