Can't add tabs after a tab is closed

Minimal working example here. Once I close one of the new tabs, the button no longer works (callback is not triggered).

from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh.models.widgets import Button
from bokeh.models import ColumnDataSource, Tabs, Panel, Range1d
from numpy.random import default_rng
rng = default_rng()

doc = curdoc()

generator_btn = Button(height=40, width=150, label="Add a new tab!")
generator_pnl = Panel(title="Start Here!", child=generator_btn)
tabs = Tabs(tabs=[generator_pnl], height=800, width=800)

class NewTab:
    def __init__(self):
        self.tab_num = 0
    
    def __call__(self):
        print("Making a new tab!")
        self.tab_num += 1
        xd = rng.random(10)
        yd = rng.random(10)
        source = ColumnDataSource(data={'x': xd, 'y': yd})
        axr = Range1d(start=0, end=1)
        fig = figure(title="Test of ad hoc tabs", x_range=axr, y_range=axr, 
                     plot_height=800, plot_width=800)
        fig.diamond(x='x', y='y', source=source)
        panel = Panel(title="New Tab #{}".format(self.tab_num), child=fig, 
                      closable=True)
        tabs.tabs.append(panel)

generator_btn.on_click(NewTab())

doc.add_root(tabs)

@gkanarek that just seems like a bug, please open an issue with all that information.

OK thanks, will do!

1 Like