Bokeh 3.x : curdoc().clear() not working anymore on my app

Hello Everyone,

I’ve got a big issue with the latest update of bokeh, indeed I use the curdoc().clear() function to dynamically change the graphics, everything is fine with 2.4.3 but it is not working anymore with 3.x update.
Does anyone encounter the same behavior ?

Many thanks

Hi @johann in order to be able to help we we really have to have to have a Minimal Reproducible Example that can actually be run to investigate.

Many thanks Bryan,

I’ve just taken a silly example, but even this simple one is not working anymore on my computer : if you type clear in the text box (function update_title), it should simply clear the whole document. In previous Bokeh version it was fine, now I’m stuck…

import numpy as np

from bokeh.io import curdoc
from bokeh.layouts import column, row
from bokeh.models import ColumnDataSource, Slider, TextInput
from bokeh.plotting import figure

# Set up data
N = 200
x = np.linspace(0, 4*np.pi, N)
y = np.sin(x)
source = ColumnDataSource(data=dict(x=x, y=y))


# Set up plot
plot = figure(height=400, width=400, title="my sine wave",
              tools="crosshair,pan,reset,save,wheel_zoom",
              x_range=[0, 4*np.pi], y_range=[-2.5, 2.5])

plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)


# Set up widgets
text = TextInput(title="title", value='my sine wave')
offset = Slider(title="offset", value=0.0, start=-5.0, end=5.0, step=0.1)
amplitude = Slider(title="amplitude", value=1.0, start=-5.0, end=5.0, step=0.1)
phase = Slider(title="phase", value=0.0, start=0.0, end=2*np.pi)
freq = Slider(title="frequency", value=1.0, start=0.1, end=5.1, step=0.1)


# Set up callbacks
def update_title(attrname, old, new):
    plot.title.text = text.value
    if text.value =="clear":
        curdoc().clear()

text.on_change('value', update_title)

def update_data(attrname, old, new):

    # Get the current slider values
    a = amplitude.value
    b = offset.value
    w = phase.value
    k = freq.value

    # Generate the new curve
    x = np.linspace(0, 4*np.pi, N)
    y = a*np.sin(k*x + w) + b

    source.data = dict(x=x, y=y)

for w in [offset, amplitude, phase, freq]:
    w.on_change('value', update_data)


# Set up layouts and add to document
inputs = column(text, offset, amplitude, phase, freq)

curdoc().add_root(row(inputs, plot, width=800))
curdoc().title = "Sliders"

@johann It seems this is just a bug. TBH I would not judge that clear is used very much at all, so I guess a regression slipped through. Please open a GitHub Issue with this information.

Done, many thanks Bryan

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.