Sldier it not connecting to plot

Please help make this code work:
‘’’

Import Libraries

from bokeh.io import show
from bokeh.layouts import row
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, Slider
import numpy as np

Define the Inputs

x = np.array([‘Jan-2019’, ‘Feb-2019’, ‘Mar-2019’, ‘Apr-2019’, ‘May-2019’, ‘Jun-2019’, ‘Jul-2019’, ‘Aug-2019’, ‘Sep-2019’, ‘Oct-2019’, ‘Nov-2019’, ‘Dec-2019’, ‘Jan-2020’, ‘Feb-2020’, ‘Mar-2020’, ‘Apr-2020’, ‘May-2020’, ‘Jun-2020’, ‘Jul-2020’])
y = np.array([20.1, 20.7, 21.9, 18.7, 19.7, 19.1, 20.0, 18.7, 19.3, 19.3, 19.2, 18.2, 18.5, 21.1, 25.0, 24.3, 23.7, 19.9, 19.7])
source = ColumnDataSource(data=dict(x=x, y=y))

Setup Plot

p = figure(title=‘Scores’, plot_height=300, plot_width=900)
p.line(x, y, color=’#2222aa’, line_width=3)

Set up Slider

slider = Slider(title=“Trend for Months”, value=12, start=3, end=19, step=1)

Define Callback

def callback(attr, old, new):
print(N)
N = slider.value
y = y+N
source.data = dict(x=x, y=y)

Show the plot

slider.on_change(‘value’, callback)
layout = row(slider, p)
show(layout)

‘’’

First of all, please format your code using the editor tools or ``` around the code.

As to your error - you should see an error in Python console. You’re doing y - N where y is a Python list, which doesn’t support the subtraction operation.

Thank you for the prompt response. I have fixed the error that you pointed out. However, it still does not work. Doesn’t look like it is going into callback, becuase it is not printing N. Please take another look at it.

@ritesh.r.kumar

Your callback is written in python, which necessitates you running your code via bokeh serve.

Sorry, am too new to all this…would it be possible for you to help with a sample code of what needs to be done here…

Check out this section: https://docs.bokeh.org/en/latest/docs/user_guide/server.html#single-module-format

Note that you specifically need to run your script with the bokeh serve command and your script must use curdoc instead of show.

Thanks. Acted on your advice, it still did not print N, but it open a blank page http://localhost:5006/myapp.

Please take another look at the code, why is N not being printed, is something that needs to be addressed.

@ritesh.r.kumar

The print statement is in a callback. If your plot and widget are not rendering, there’s not a mechanism in your example to affect a change that triggers the callback.

As noted by @p-himik, you need to change the code to use curdoc() and add_root() to render the models per the server documentation.

You’ll need to repost your updated code for additional help with the problem, and take care to properly format it in the issue so that it can be cut-and-pasted into a file for more efficient help.