Changing text based on graph dynamically in Bokeh

Hello all,

I am trying to change values in text based on graph in Bokeh.

I have figured out that I can do this using Callbacks but I can’t seem to get the right code for it.

Below is the code that I am working on.

Any help would be appreciated.



import numpy as np

from import output_file, save

from bokeh.plotting import figure

from bokeh.layouts import widgetbox, row

from bokeh.models.widgets import Paragraph

x = np.array([1,2,3,4,5])

y = np.array([8,6,5,2,3])

plot = figure(plot_width = 400, tools = ‘pan, box_zoom, reset, hover, save’)

plot.line(x, y)


p = Paragraph(text="""I need this text to change dynamically when the plot is changed. For this example, those values

are x and y respectively. I have calculated the just the mean for now but I need the mean to change based on the points visible on the plot.""" + str(np.mean(x + y)),

width=200, height=100)

save(row(widgetbox§, plot))