I have found the taylor-server example on this list and I modified it tying to fit my need and it is working well.
However, when I run the modified script, unless I stop the server and restart, when I run the following python script, the same plot plus slider is added to a previous plot + slider …
Unfortunately I wasn’t able to quite understand the proper usage of session and document, are there some references to show exactly how these two need to be properly used ?
Here is the code below, as you can see it is mostly taken from the taylor-server example … thanks !
import numpy as np
from bokeh.browserlib import view
from bokeh.document import Document
from bokeh.models.glyphs import Line
from bokeh.models import Plot, DataRange1d, LinearAxis, ColumnDataSource, Grid, Legend
from bokeh.session import Session
from bokeh.models.widgets import Slider, TextInput, HBox, VBox, Dialog
document = Document()
session = Session()
session.use_doc(‘my server’)
session.load_document(document)
x = np.arange(0, 4*np.pi, np.pi/10)
order = 1
def update_data():
fy = order*np.sin(x)
source.data = dict(x=x, fy=fy)
slider.value = order
session.store_document(document)
source = ColumnDataSource(data=dict(x=, fy=, ty=))
xdr = DataRange1d()
ydr = DataRange1d()
plot = Plot(x_range=xdr, y_range=ydr, plot_width=800, plot_height=400)
line_f = Line(x=“x”, y=“fy”, line_color=“blue”, line_width=2)
line_f_glyph = plot.add_glyph(source, line_f)
plot.add_layout(line_f_glyph)
xaxis = LinearAxis()
plot.add_layout(xaxis, ‘below’)
yaxis = LinearAxis()
plot.add_layout(yaxis, ‘left’)
def on_slider_value_change(obj, attr, old, new):
global order
order = new
update_data()
slider = Slider(start=0, end=20, value=order, step=1, title=“Order:”)
slider.on_change(‘value’, on_slider_value_change)
layout = VBox(slider, plot)
document.add(layout)
update_data()
if name == “main”:
link = session.object_link(document.context)
view(link)
session.poll_document(document)