I have an interactive standalone .html
with three tabs. This is a pseudo-code example as I have to simplify it to minimal in order to not write 1000 line codes. All of the plots works perfectly individually, the problem is when I'm trying to run the cell which put them together in an .html
file:
I have been looking for similar solutions like this, this, and others without success. These are the plots and datatables to show in the html (they work perfectly when I plot them individually):
Plot 1 in tab 1:
TOOLTIPS = [("Percentage", "@pct{0.2%}")]
data = table1.copy()
factors = data["YYYY_MM"].tolist()
p = figure(x_range=FactorRange(*factors),
y_axis_label="label",
toolbar_location=None,
tooltips=TOOLTIPS)
p.vbar(x="YYYY_MM", top="a",source=data)
p.vbar(x="YYYY_MM", top="b", source=data)
p.extra_y_ranges = {"pct": Range1d(start=0, end=1)}
p.add_layout(LinearAxis(y_range_name="pct", axis_label="label2"), 'right')
p.line(x="YYYY_MM", y="pct", source = data, y_range_name='pct')
p.line(x="YYYY_MM", y="pct2",source = data, y_range_name='pct2')
p.add_layout(p.legend[0], 'right')
plot1_tab1= p
show(p)
Plot 2 in tab 1:
data = table1.copy()
p = figure()
p.vbar(x="some_x", top="some_y", source=data)
p.xgrid.grid_line_color = None
p.y_range.start = 0
plot2_tab1= p
show(p)
Data table 1 in tab 1:
data = table4.copy()
source = ColumnDataSource(data)
columns = [
TableColumn(field="some_column", title="some title"),
TableColumn(field="some_column", title="some title")
]
datatable1_tab1 = DataTable(source=source, columns=columns)
show(datatable1_tab1)
Plot 3 in tab 2:
data = table2.copy()
factors = data.index.tolist()
p = figure(some code)
for some_loop_over_something:
p.line()
p.add_layout(p.legend[0], 'right')
plot3_tab2 = p
show(p)
plot 4 in tab 2:
data = table3.copy()
factors = data.index.astype(str).tolist()
p = figure(some code)
colors = itertools.cycle(palette)
call_centers = data.columns
for some loop:
p.line(some code)
p.add_layout(p.legend[0], 'right')
p.y_range.start = 0
plot4_tab2 = p
show(p)
Here is the construction of the three tabs for the html:
tab 1:
t1=column(Div(text="<h2>some text<h2>",width=600))
t12=column(Div(text="<h2> <h2>",width=50))
t01=column(Div(text="<h2> <h2>",width=100))
t2=column(Div(text="<h2>some text<h2>",width=600))
t22=column(Div(text="<h2> <h2>",width=50))
t02=column(Div(text="<h2> <h2>",width=100))
t3=column(Div(text="<h2>some text<h2>",width=600))
t32=column(Div(text="<h2> <h2>",width=50))
t03=column(Div(text="<h2> <h2>",width=100))
lay1=layout([[t1],[t01,plot1_tab1],
[t12],[t2],[t02,plot2_tab1],
[t3],[t32],[t03,datatable1_tab1]])
tab 2:
t0=column(Div(text="<h2>some text<h2>", width=800))
t1=column(Div(text="<h3>1some text<h3>",width=600))
t01=column(Div(text="<h3> some text<h3>",width=100))
t12=column(Div(text="<h3> some text<h3>",width=50))
t2=column(Div(text="<h3>some text<h3>",width=600))
t02=column(Div(text="<h3>some text<h3>",width=100))
lay2=layout([[t0],[t1],[t01,plot3_tab2],
[t12],[t2],[t02,plot4_tab2]])
tab 3:
source = ColumnDataSource(data)
columns = [
TableColumn(field="some column", title="some title"),
TableColumn(field="some column", title="some title"),
TableColumn(field="some column", title="some title"),
]
data_table = DataTable(source=source, columns=columns, width=400, height=400)
show(data_table)
lay3=data_table
And the code that put all together (here is the problem):
output_notebook()
output_file('output/test.html', title='Dashboard', mode='inline')
first = Panel(child=row(lay1), title='title1')
second = Panel(child=row(lay2), title='title2')
third = Panel(child=row(lay3), title='title3')
tabs = Tabs(tabs=[first, second, third])
show(tabs)
I don't know what is the problem as it worked fine before. I did some changes in layer1 and just stopped giving the html with the error Models must be owned by only a single document, TableColumn(id='1441', ...) is already in a doc
and sometimes is not TableColumn
but something else.
Also, if I "Run and Restart All" the jupyter notebook, it gives every plot and table just fine in a new browser window. Once the code reaches the last cell (the one that creates the html) it raises the error, then if I try to run any other bokeh-plot that worked just fine before running that last cell, it raises the same error but with different object (i.e. instead of TableColumn(id='1441', ...)
is Div(id='2327', ...)
). However, if I run:
from bokeh.io import reset_output
reset_output()
The individual bokeh plots are plotted again without problem once I run their cells, but if I run the cell that put all together.. again, raises the error.
I thought the problem could be local, so I tried restarting the computer and restarting Anaconda and didn't work. Can I change the address of the folder where the html is temporarly created? Because the file (output/test.html
) doesn't appear anywhere no matter what I do.
The bokeh version is 2.2.3.
UPDATE: Tried solution
I tried changuing the last cell to this:
# output_notebook()
# output_file('output/test.html', title='Dashboard', mode='inline')
first = Panel(child=row(lay1), title='Modelo')
second = Panel(child=row(lay2), title='Contactabilidad')
third = Panel(child=row(lay3), title='Diccionario')
tabs = Tabs(tabs=[first, second, third])
output_file("output_file_name.html")
save(tabs)
And still gives the same type of error.