What am I missing here guys? This should work, I feel like I’ve been looking at it too long.
This should just be a dot that revolves in a circle with the slider value, but the callback isn’t working.
import numpy as np
import pandas as pd
from bokeh.models import CustomJS, Slider
from bokeh.layouts import widgetbox, layout
from bokeh.plotting import figure, show, ColumnDataSource
#constants
cent_x = 3
cent_y = 3
radius = 3
#build coord dataframe
df = pd.DataFrame()
theta = np.linspace(0,(2*np.pi),50)
df[‘x’] = radius * np.cos(theta) + cent_x
df[‘y’] = radius * np.sin(theta) + cent_y
#init source (all data)
source = ColumnDataSource(df)
#rend source/build plot
mask = df.index == 0
rend_source = ColumnDataSource(df.loc[mask])
plot = figure(plot_width=400, plot_height=400)
plot.circle(‘x’,‘y’,color=‘red’,size=10,source=rend_source)
#add slider and callback
code = “”"
var v = cb_obj.value;
var s1data = s1.data;
var s2data = s2.data;
s2data[‘x’].push(s1data[‘x’][v]);
s2data[‘y’].push(s1data[‘y’][v]);
s2data[‘index’].push(s1data[‘index’][v]);
s2.change.emit();
“”"
callback = CustomJS(
args=dict(
s1=source,
s2=rend_source),
code=code)
slider = Slider(
start=df.index.min(), end=df.index.max(),
value=0, step=1, title=‘slider’, callback=callback
)
#layout and show plot
controls = widgetbox(slider, width=400)
layout = layout([
[plot],
[controls],
])
show(layout)
``