☰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

Updating Span in add_layout

Community Support
Laura_Suttle
Laura_Suttle

I have the following two functions for making a plot and updating it

def make_bar(df, x, y, label, color, color_mapper):

“”" Creates a bar chart in bokeh"“”

p = figure(title=“Current Probability and Recommendations”,

x_range= df.data, webgl=True,

#plot_width=800,

plot_height=500)

labels = LabelSet(x=x, y=y, text=label, text_font_size = “9pt”, level=‘glyph’,

x_offset=-25, y_offset=0, source=source, render_mode=‘canvas’)

#p.segment(df.data, df.high, df.date, df.low, color=“black”)

p.vbar(x= x,

width=0.5,

bottom=0,

top=y,

#color=“darkgreen”,

fill_color={‘field’: color, ‘transform’: color_mapper},

source = df)

p.add_layout(labels)

p.yaxis[0].axis_label = ‘Probability of Success’

hline = Span(location=source.data[y][0], dimension=‘width’,

line_color=‘black’, line_width=2, line_dash = “dotted”)

p.add_layout(hline)

return p

def update_plot():

“”" Updates dashboard when Update Button

is pressed. “”"

f = mapFilters()

model_input_vector = models.make_vector(mapPredictors(f)) # vector formated for input

output = models.make_changes(model_input_vector, rf, lr) # get recommendations

src = ColumnDataSource(data=output) # convert to bokeh column source

source.data.update(src.data) # update primary source with new one

hline.location=src.data[‘Score’][0]

prob = rf.predict_proba(model_input_vector)[:,1] # probability of current model, if needed

updating div

recDiv.text = t.render(df=output)

I am trying to update the Span that I am using to create a dotted line. I used this code to add it, as shown above:

hline = Span(location=source.data[y][0], dimension=‘width’,

line_color=‘black’, line_width=2, line_dash = “dotted”)

p.add_layout(hline)

You can see in my update_plot function that I am trying to update the location, but it’s not working (not that I expected it to). Everything else in my plot updates when I update the source data using source.data.update(src.data).

How do you update the location of spans on data update?

⌁   Link to post
Laura_Suttle
Laura_Suttle

Resolved this by passing hline in the return and then updating the location of that variable. Will leave for posterity.

···

On Monday, April 24, 2017 at 10:09:44 PM UTC-4, Laura Suttle wrote:

I have the following two functions for making a plot and updating it

def make_bar(df, x, y, label, color, color_mapper):

“”" Creates a bar chart in bokeh"“”

p = figure(title=“Current Probability and Recommendations”,

x_range= df.data, webgl=True,

#plot_width=800,

plot_height=500)

labels = LabelSet(x=x, y=y, text=label, text_font_size = “9pt”, level=‘glyph’,

x_offset=-25, y_offset=0, source=source, render_mode=‘canvas’)

#p.segment(df.data, df.high, df.date, df.low, color=“black”)

p.vbar(x= x,

width=0.5,

bottom=0,

top=y,

#color=“darkgreen”,

fill_color={‘field’: color, ‘transform’: color_mapper},

source = df)

p.add_layout(labels)

p.yaxis[0].axis_label = ‘Probability of Success’

hline = Span(location=source.data[y][0], dimension=‘width’,

line_color=‘black’, line_width=2, line_dash = “dotted”)

p.add_layout(hline)

return p

def update_plot():

“”" Updates dashboard when Update Button

is pressed. “”"

f = mapFilters()

model_input_vector = models.make_vector(mapPredictors(f)) # vector formated for input

output = models.make_changes(model_input_vector, rf, lr) # get recommendations

src = ColumnDataSource(data=output) # convert to bokeh column source

source.data.update(src.data) # update primary source with new one

hline.location=src.data[‘Score’][0]

prob = rf.predict_proba(model_input_vector)[:,1] # probability of current model, if needed

updating div

recDiv.text = t.render(df=output)

I am trying to update the Span that I am using to create a dotted line. I used this code to add it, as shown above:

hline = Span(location=source.data[y][0], dimension=‘width’,

line_color=‘black’, line_width=2, line_dash = “dotted”)

p.add_layout(hline)

You can see in my update_plot function that I am trying to update the location, but it’s not working (not that I expected it to). Everything else in my plot updates when I update the source data using source.data.update(src.data).

How do you update the location of spans on data update?

⌁   Link to post

End of archived discussion · Replies are disabled