I am using Bokeh to produce an interactive time-series graph. There can be n number of series displayed simultaneously. Each series will display from t= 0 to t = x, with x being the value created by a slider.
I'm using ColumnDataSource to contain it all, MultiLine glyph to display the series, Slider for the slider and CustomJS to control the update interaction.
from bokeh.models import CustomJS, ColumnDataSource, Slider, Plot
from bokeh.models.glyph import MultiLine
from bokeh.io import show
from bokeh.layouts import column
data_dict = {'lons':[[-1.0, -1.1, -1.2, -1.3, -1.4], [-1.0, -1.1, -1.25, -1.35, -1.45]], 'lats':[[53.0, 53.1, 53.2, 53.3, 53.4], [53.05, 53.15, 53.25, 53.35, 53.45]]}
source = ColumnDataSource(data_dict)
p = Plot(title = None, plot_width = 400, plot_height = 400)
glyph = MultiLine(xs = 'lons', ys = 'lats')
p.add_glyph(source, glyph)
callback = CustomJS(args = dict(source = source), code = """
var data = source.data;
var time = time.value;
var lons = data['lons']
var lats = data['lats']
var runners = lons.length()
var new_lons = []
var new_lats = []
for(i=0; i<runners; i++{
var runner_lons = lons[i].slice(0, time)
var runner_lats = lats[i].slice(0, time)
new_lons.push(runner_lons)
new_lats.push(runner_lats)
}
lons = new_lons
lats = new_lats
source.change.emit();
""")
slider = Slider(start = 0, , end = 5, value = 0, step = 1, callback = callback)
layout = column(p, slider)
callback.args["time"] = slider
show(layout)
This code renders the graph, with both lines drawn covering all points in source.data.
Moving the slider will update the data in lons & lats as intended, but the graph display does not update.
Pointers, recommendations, suggestions, explanations all very gratefully received!