I am trying to update y_range for my Bokeh plot using CustomJS which should update based on the selection from the dropdown widget. I tried using y_range.factors = factors in CustomJS, but it does not seem to be working. My axis is categorical. It would be great if someone could help me in this. Here’s my code:
p3 = figure(title="title",
x_axis_location="below", plot_width=400, plot_height=800,
x_range=sensors, y_range=FactorRange(*run_ids),
tools=TOOLS, toolbar_location='above',
tooltips=[('Tooltip', '@tooltip'])
callback = CustomJS(args=dict(source1 = Overall, sc1 = Curr, plot = p3), code="""
console.log(plot)
var f = cb_obj.value
console.log(f)
sc1.data['run_id']=[\*]
for(var i = 0; i <= source1.get_length(); i++){
if (source1.data['computer_name'][i] == f){
sc1.data['run_id'].push(source1.data['run_id'][i])
}
}
console.log(plot.y_range)
plot.y_range.factors = sc1.data['run_id'].filter((v, i, a) => a.indexOf(v) === i);
console.log(plot.y_range)
plot.y_range.change.emit();
""")
p3.rect(x="sensor", y="run_id", width=1, height=1,
source=Curr,
fill_color={'field': 'avg', 'transform': mapper},
line_color=None)
menu = Select(options=list(df['computer_name'].unique()),value=laptop_list[0], title = 'Laptop')
menu.js_on_change('value', callback)
layout=column(menu, p3)
show(layout)
It throws an error in console when setting y_range.factors:
“cannot read property ‘length’ of undefined”
Please let me know if I can improve on submitting a question. Thank you!