☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Can't add tabs after a tab is closed

Community Support
gkanarek
gkanarek

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)
⌁   Link to post

End of archived discussion · Replies are disabled