☰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

How to update document while showing it in notebook

Community Support
jareducherek
jareducherek

I want to directly update parameters of a model within a document. A simple example is updating the title of the model when a button is pressed. I have been able to actively update the doc as long as I alter the data of the model, but not other parameters.

Example for bokeh 1.2.0:

import bokeh
from bokeh.io import show, output_notebook
from bokeh.plotting import figure
from bokeh.models import Button, Panel, Tabs
from bokeh.layouts import row, column
from bokeh.themes import Theme

output_notebook()

def modify_doc(doc):
    #Figure
    plot = figure(title='start', background_fill_color="#fafafa", plot_height = 300, active_scroll = 'wheel_zoom')

    #--------------------------------------------- 
    #Set up widgets
    #--------------------------------------------- 
    button = Button(label='► Play')
    
    #--------------------------------------------- 
    #Set up callbacks
    #---------------------------------------------  
    def button_animate():
        '''changes play/pause button to correct graphic when clicked
        
        '''
        print(f'plot title before change: {plot.title.text}')
        print(f'doc title before change: {doc._roots[0].children[1].tabs[0].child.title.text}')
        t = bokeh.models.annotations.Title()
        if button.label == '► Play':
            button.label = '❚❚ Pause'
            t.text = 'pause'
            #plot.title = t
            #doc._roots[0].children[1].tabs[0].child.title = t
        else:
            button.label = '► Play'
            t.text = 'play'
            #plot.title = t
            #doc._roots[0].children[1].tabs[0].child.title = t
        
        plot.title = t
        event = bokeh.document.events.ModelChangedEvent(doc, plot, 'title', plot.title, t, None)
        doc._trigger_on_change(event)
        
        print(f'plot title after change: {plot.title.text}')
        print(f'doc title after change: {doc._roots[0].children[1].tabs[0].child.title.text}')
        print('-----------------')
        
        global temp
        temp = doc
            
            

    #--------------------------------------------- 
    #Define Actions on change
    #--------------------------------------------- 
    button.on_click(button_animate)

    
    #--------------------------------------------- 
    #Set up layouts and add to document
    #--------------------------------------------- 
    inputs = row(button, name = 'main_widgets')
    tab1 = Panel(child = plot, title = 'Network Graph', name = 'panel_graph')
    tabs = Tabs(tabs = [tab1], name = 'main_tabs')
    
    #--------------------------------------------- 
    #Finalize document setup
    #---------------------------------------------  
    doc.add_root(column(inputs, tabs, width=800, name = 'main_display'))
    doc.title = "graph"
    
    
show(modify_doc)
⌁   Link to post
Bryan
Bryan

You are working too hard. You should update the text of the Title that the plot already has:

def button_animate():
    if button.label == '► Play':
        button.label = '❚❚ Pause'
        plot.title.text = 'pause'
    else:
        button.label = '► Play'
        plot.title.text = 'play'

The general, always-applicable best-practice rule with Bokeh is: always make the smallest change possible. In this context (and usually) that means updating simple properties of existing objects, not trying to replace entire objects.

⌁   Link to post

End of archived discussion · Replies are disabled