I m using bokeh to plot my chart. So I need to have an Image as background, and I need to make http request every X second, and in base of response of http request I will change the figure image background.
So this is the code:
img_yellow = "http://localhost:8000/static/images/semaforo_yellow.png"
img_green = "http://localhost:8000/static/images/semaforo_verde.png"
img_red = "http://localhost:8000/static/images/semaforo_rosso.png"
p = figure(x_range=(0, 1), y_range=(0, 1))
p.image_url(url=[img_yellow], x=0, y=1)
source = AjaxDataSource(data_url="http://localhost:8000/rt/semaforo",
polling_interval=50000)
p.circle('x', 'y', source=source)
print_button = Button(label="Print")
print_button.js_on_click(CustomJS(args=dict(source=ecg_source, plot=p), code="""
console.log("pippoprint");
plot.url = "http://localhost:8000/static/images/semaforo_rosso.png";
plot.image_url = "http://localhost:8000/static/images/semaforo_rosso.png";
console.log(plot);
plot.change.emit();
"""))
For the moment to test the application, I used a BUTTON and if I click on this button I should to change the image, but not are working now.
this is not youre looking for but with server side
img_yellow = "http://localhost:8000/static/images/semaforo_yellow.png"
img_green = "http://localhost:8000/static/images/semaforo_verde.png"
img_red = "http://localhost:8000/static/images/semaforo_rosso.png"
def change_img(attr, old, new):
p.image_url.url = img_yellow
p = figure(x_range=(0, 1), y_range=(0, 1))
p.image_url(url=[img_yellow], x=0, y=1)
source = AjaxDataSource(data_url="http://localhost:8000/rt/semaforo",
polling_interval=50000)
p.circle('x', 'y', source=source)
print_button = Button(label="Print")
print_button.on_click(change_img)