Estoy usando bokeh para trazar mi gráfico. Entonces, necesito tener una imagen como fondo, y necesito hacer una solicitud http cada X segundo, y en base a la respuesta de la solicitud http, cambiaré el fondo de la imagen de la figura.
Así que este es el código:
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(); """))Por el momento para probar la aplicación, utilicé un BOTÓN y si hago clic en este botón debería cambiar la imagen, pero ahora no están funcionando.
esto no es lo que estás buscando pero con el lado del servidor
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)