Skip to content

How to Fix Python Bokeh Server Not Updating

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix Python Bokeh Server Not Updating. We cover key concepts, practical examples, and best practices.

Bokeh server apps appear static when the data source is not properly linked to the plot, the document is not modified correctly, or the update callback does not run.

The Wrong Way

from bokeh.plotting import figure, curdoc
from bokeh.models import ColumnDataSource
import random

source = ColumnDataSource(data={"x": [], "y": []})
p = figure()
p.circle("x", "y", source=source)

def update():
    source.data["x"].append(random.random())
    source.data["y"].append(random.random())

# Forgot to add periodic callback
curdoc().add_root(p)

The plot stays empty because update() is never called.

The Right Way

from bokeh.plotting import figure, curdoc
from bokeh.models import ColumnDataSource
from bokeh.layouts import column
from bokeh.server.server import Server
import random

source = ColumnDataSource(data={"x": [], "y": []})
p = figure()
p.circle("x", "y", source=source)

def update():
    new_x = random.random()
    new_y = random.random()
    source.stream({"x": [new_x], "y": [new_y]}, rollover=100)

curdoc().add_root(p)
curdoc().add_periodic_callback(update, 1000)

The plot updates every second with new points.

Prevention Tips

  • Use source.stream() to push data without replacing existing data.
  • Use curdoc().add_periodic_callback() for timed updates.
  • Use source.patch() for targeted updates to specific indices.
  • Use curdoc().add_timeout_callback() for one-shot delayed updates.
  • Always modify source.data through Bokeh's methods, not direct dict assignment.

Common Mistakes with bokeh server

  1. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  2. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  3. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks

These mistakes appear frequently in real-world PYTHON code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What is the difference between ColumnDataSource and regular dict?

ColumnDataSource triggers plot updates when data changes. Regular dict does not notify the plot. Always use ColumnDataSource for data that the plot displays.

How do I run a Bokeh server?

Use bokeh serve app.py from the command line. The server runs on localhost:5006. Use --allow-<a href="/apis/websocket/">websocket</a>-origin for custom domains.

Why does my Bokeh plot not update when data changes?

The data object must be the same object passed to the glyph. Use source.data = new_data to replace all data or source.stream() to append. Direct mutation of source.data["x"] may not trigger updates.

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro