python - Dynamically add tabs with figures in bokeh - Stack Overflow

I have a bokeh server application (3.7.0). When the application is started one tab is shown and when th

I have a bokeh server application (3.7.0). When the application is started one tab is shown and when the execute button is pressed another tab is added. It works as long as the second tab does not contain figures. How can I solve this?

    from bokeh.io import curdoc
    from bokeh.layouts import layout
    from bokeh.models.widgets import Div, Button
    from bokeh.models import Tabs, TabPanel
    from bokeh.plotting import figure
 
def tab1():

    w_1 = Div(text="<b>T1</b>",
          styles={'font_family': 'arial', 'text_align': 'center', 'font-size': '20px', 'color': 'blue'}, width=200, height=100)
    p1 = figure(width=300, height=300)
    p1.scatter([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5)
    w_execute = Button(label='Execute', name='Execute')

    l1 = layout([[w_1],
                [p1],
                [w_execute]])
    t1 = TabPanel(child=l1,title="T1")
    tabs = Tabs(tabs=[t1])
    
    def func_run(new):
        add_t2(t1)

    w_execute.on_click(func_run)
    curdoc().add_root(tabs)

def add_t2(t1):
    curdoc().clear()
    t2 = tab2()
    tabs = Tabs(tabs = [t1, t2])
    curdoc().add_root(tabs)

def tab2():
    w_2 = Div(text="<b>T2</b>",
          styles={'font_family': 'arial', 'text_align': 'center', 'font-size': '20px', 'color': 'blue'}, width=200, height=100)
    p2 = figure(width=300, height=300)
    p2.scatter([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5)

    # l2 = layout([[w_2],
    #             [p2]]) # Does not work
    l2 = layout([[w_2]]) # Works
    t2 = TabPanel(child=l2,title="T2")
    return t2

tab1()

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744203300a4562983.html

相关推荐

  • python - Dynamically add tabs with figures in bokeh - Stack Overflow

    I have a bokeh server application (3.7.0). When the application is started one tab is shown and when th

    8天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信