Can't update x_range/y_range using CustomJS and select from dropdown

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="""
var f = cb_obj.value
for(var i = 0; i <= source1.get_length(); i++){
    if (['computer_name'][i] == f){['run_id'].push(['run_id'][i])
plot.y_range.factors =['run_id'].filter((v, i, a) => a.indexOf(v) === i);

p3.rect(x="sensor", y="run_id", width=1, height=1,
       fill_color={'field': 'avg', 'transform': mapper},

menu = Select(options=list(df['computer_name'].unique()),value=laptop_list[0], title = 'Laptop')

menu.js_on_change('value', callback)
layout=column(menu, p3)

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!

Hi @Yogi please edit your post to use code formatting so that the code is intelligible (either with the </> icon on the editing toolbar, or triple backtick ``` fences around the code blocks)

Hi Bryan, thank you for the feedback. I changed it.

Also, figured out the solution. Instead of plot.y_range.change.emit() it needs to be plot.change.emit()

@Yogi I am surprised that you need either. Are you saying it does not work if you delete the emit line altogether?

Sorry for the delayed response @Bryan. Yes, if I remove emit line, the plot does not update.

That’s strange, but a would need complete minimal reproducer to investigate further.

I will test this with a simple dataset today and will let update you with what I find.