1
votes

I having a problem with the callback, I got everything worked expect the part when the graph doesn't update even thou the array is updated when I change the slider.

import numpy as np

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

data = {'x_values': [0,0,2,2,4,4],
        'y_values': [10,0,0,5,5,10]} #Seting up data

source = ColumnDataSource(data=data) # Map plot

plot = figure(title="Step Well",
              tools="save,wheel_zoom")

plot.line('x_values', 'y_values',source=source)

def update_data(attrname, old, new):
    Step = StepHeight.value

    x = [0,0,2,2,4,4]
    y = [10,0,0,Step,Step,10]
    source.data = ColumnDataSource(dict(x=x, y=y))
    source.on_change('value', update_data)

StepHeight = Slider(title="Step Height", 
                    value=4.0, 
                    start=2.0, end=6.0, step=0.2)
# Set up layouts and add to document
inputs = widgetbox(StepHeight)

layout = row(inputs, plot)

curdoc().title = "Sliders"
curdoc().add_root(layout)
1

1 Answers

1
votes

You were trying to make source.data a column data source but source should be the column data source. Source.data is just a dictionary. I changed some things in your code and it should work fine now.

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

data = {'x_values': [0,0,2,2,4,4],
        'y_values': [10,0,0,5,5,10]} #Seting up data

source = ColumnDataSource(data=data) # Map plot

plot = figure(title="Step Well",
              tools="save,wheel_zoom")

plot.line('x_values', 'y_values',source=source)

def update_data(attrname, old, new):
    y = [10,0,0,new,new,10]
    source.data['y_values'] = y

StepHeight = Slider(title="Step Height", 
                    value=4.0, 
                    start=2.0, end=6.0, step=0.2)

StepHeight.on_change('value', update_data)

# Set up layouts and add to document
inputs = widgetbox(StepHeight)

layout = row(inputs, plot)

curdoc().title = "Sliders"
curdoc().add_root(layout)