Slider fails to update plot using Bokeh server

Hi. I’m new to Bokeh and would like to learn how to create a plot with a slider that’s deployed using the Bokeh server. I found three examples of code on the internet and managed to get the scripts to open in browser windows using the Anaconda Command Prompt and Bokeh Serve command. Unfortunately though, for all three code examples, the number of glyphs in the plots do not change when I move the slider value. Everything else looks fine, except the plots do not update when I move the slider. I have the latest version of Bokeh installed and tried using several different internet browsers. I’m sure it is an easy fix, but just not sure where to start. One of the codes (from DataCamp) that I tried without success is below. Any help would be appreciated. Thank you.

from bokeh.io import curdoc
from bokeh.layouts import column
from bokeh.models import ColumnDataSource, Slider
from bokeh.plotting import figure
from numpy.random import random

N = 300
source = ColumnDataSource(data={'x': random(N), 'y': random(N)}) 

# Create plots and widgets
plot = figure()
plot.circle(x= 'x', y='y', source=source)

slider = Slider(start=100, end=1000, value=N, step=10, title='Number of points')

# Add callback to widgets def callback(attr, old, new):     
def callback(attr, old, new):
    N = slider.value
    source.data={'x': random(N), 'y': random(N)}
    slider.on_change('value', callback) 
# Arrange plots and widgets in layouts
layout = column(slider, plot) 
curdoc().add_root(layout)

Hi @gibsms

The issue with the example is where the callback is defined. Note that the callback is being registered inside of the callback definition (because of the indentation of the last line). Move the slider.on_change() call outside of the function by un-indenting it.

Also, you can use the following line to set the variable N inside of the callback

N = new

where new is the updated (new) value of the slider’s value attribute.

Hi. Thank you for your help. That was a copy paste error on my behalf. Good to know it was something simple. I will use N = new from now on as well. Cheers.