☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Slider not updating multi line plot!

Community Support
Akshay_Bung
Akshay_Bung
numlines=len(df.columns)
col = list(df.columns)
ind = list(df.index)
source = ColumnDataSource(df)
all_colors = [k for k,v in pltc.cnames.items()]
colors = all_colors[:numlines]

legend_it = []
p = figure(width=1250, height=1100, x_axis_type="datetime", title="Monthly Data Usage", title_location='above')
p.xaxis.axis_label = 'Date Range'
p.yaxis.axis_label = 'Data Used'

for (cl, color) in zip(col, colors):
    c = p.line(x='deviceDUDay', y=cl, line_width=2, alpha=0.8, source=source, color = color )
    legend_it.append((cl, [c]))
    p.add_tools(HoverTool(
            renderers=[c],
            tooltips=[('datetime','@deviceDUDay{%Y-%m-%d}'),(cl, f'@{cl}')],
            formatters={'deviceDUDay': 'datetime'}))
print(source.data.keys())

legend = Legend(items=legend_it, location=(300, 0), spacing = 5)
p.add_layout(legend, 'right')

p.legend.label_text_font_size = '10px'
p.legend.location='center'
p.legend.click_policy="hide"

slider = Slider(start=0, end=10000, step=100, value=200)

def callback(attr, old, new):
    value = slider.value
    new_data = df.loc[:, (df.sum() >= value)]
    source.data = new_data

slider.on_change('value', callback)

layout = column(widgetbox(slider), p)
curdoc().add_root(layout)


The multiline plotting works.
I want to add slider, based on the slider value, it would show the number of line plots accordingly. But when i add the slider functionality, the plot doesn’t change.

Also I am running it using bokeh serve, since its a python callback.

I feel the source data doesn’t get updated which plotting lines in a loop.
I’ve tried printing out the source data from callback function, it displays the proper truncated data frame according to the slider value properly, i.e., if I hover over the plots, the hovertips shows value of line plots based on slider which is nice, But the plots which does not satisfy slider value are not hiding. Am I missing something?

Please help!
Thank you!

⌁   Link to post
p-himik
p-himik

Your code produces JS console errors. You cannot remove a column from a data source that’s being used by something.
In your case, the simplest thing is to not change the data but rather to change the visible property of each particular renderer.

⌁   Link to post
Akshay_Bung
Akshay_Bung

i am still not being able to make it work! Should i update the visible property in callback function? Also should I change the logic from looping over and making individual line glyph to making use of multi_line glyph?
Thank you!

⌁   Link to post
p-himik
p-himik

Should i update the visible property in callback function?

Exactly.

should I change the logic from looping over and making individual line glyph to making use of multi_line glyph?

It depends on various factors. For example, if you decide to use multi_line, you won’t be able to hide individual lines with just visible.

⌁   Link to post

End of archived discussion · Replies are disabled