का उपयोग करके प्लॉट को गतिशील रूप से जोड़ें/हटाएं मेरा प्रश्न another thread को बोके 0.7.1 का उपयोग करके काफी समान है, लेकिन बोके सर्वर के लिए एपीआई 0.12.0 में पर्याप्त बदल गया है, कि मैं संघर्ष कर रहा हूं नए संस्करण के जवाब को अनुकूलित करने के लिए।गतिशील रूप से 'बोके सेवा' (बोकेह 0.12.0)
संक्षेप में, मेरे पास एक पृष्ठ है जो टाइमस्ट्रीम प्लॉट्स के ग्रिड के साथ एक फ़ाइल है जो लगातार अद्यतन होने वाली फ़ाइल से डेटा खींचती है। पृष्ठ में एक मल्टी सिलेक्ट मेनू है जो मेरी फ़ाइल में सभी चर सूचीबद्ध करता है। मैं मेनू में विभिन्न चर का चयन करने में सक्षम होना चाहता हूं, एक बटन दबाएं, और फिर मौजूदा चर के भूखंड गायब हो जाएं और नए टाइमस्ट्रीम द्वारा प्रतिस्थापित किया जाए, जहां भूखंडों की संख्या अलग हो सकती है। मैं अपनी स्क्रिप्ट bokeh serve --show script.py
रैपर के साथ चला रहा हूं।
इस पर मेरे शुरुआती प्रयास में, मैंने एक ईवेंट हैंडलर को एक बटन पर असाइन किया, जो 'curdoc' को साफ़ करता है और फिर मल्टीसेलेक्ट से नए चुने गए चर के लिए प्लॉट जोड़ता है। यह चलता है, लेकिन भूखंडों की संख्या अद्यतन नहीं होती है। जाहिर है, मैं उस कॉल को याद कर रहा हूं जो किसी भी तरह से पेज लेआउट रीफ्रेश करने के लिए सर्वर को बताता है।
import numpy as np
from bokeh.driving import count
from bokeh.plotting import figure, curdoc
from bokeh.layouts import gridplot
from bokeh.models import Slider, Column, Row, ColumnDataSource, MultiSelect, Button
from netCDF4 import Dataset
import datetime
# data
#data = Dataset('/daq/spt3g_software/dfmux/bin/output.nc', 'r', format='NETCDF4')
data = Dataset('20160714_warm_overbiased_noise.nc', 'r', format='NETCDF4')
vars = data.variables.keys()[1:11]
# plots
d = {('y_%s'%name):[] for name in vars}
d['t'] = []
source = ColumnDataSource(data=d)
figs = [figure(x_axis_type="datetime", title=name) for name in vars]
plots = [f.line(x='t', y=('y_%s'%f.title.text), source=source, color="navy", line_width=1) for f in figs]
grid = gridplot(figs, ncols=3, plot_width=500, plot_height=250)
# UI definition
npoints = 2000
slider_npoints = Slider(title="# of points", value=npoints, start=1000, end=10000, step=1000.)
detector_select = MultiSelect(title="Timestreams:", value=[], options=vars)
update_detector_button = Button(label="update detectors", button_type="success")
# UI event handlers
def update_detector_handler():
global figs, plots, grid, source
d = {('y_%s'%name):[] for name in detector_select.value}
d['t'] = []
source = ColumnDataSource(data=d)
figs = [figure(x_axis_type="datetime", title=name) for name in detector_select.value]
plots = [f.line(x='t', y=('y_%s'%f.title.text), source=source, color="navy", line_width=1) for f in figs]
grid = gridplot(figs, ncols=3, plot_width=500, plot_height=250)
curdoc().clear()
curdoc().add_root(Column(Row(slider_npoints, Column(detector_select, update_detector_button)), grid))
update_detector_button.on_click(update_detector_handler)
# callback updater
@count()
def update(t):
data = Dataset('20160714_warm_overbiased_noise.nc', 'r', format='NETCDF4')
#data = Dataset('/daq/spt3g_software/dfmux/bin/output.nc', 'r', format='NETCDF4')
npoints = int(slider_npoints.value)
new_data = {('y_%s'%f.title.text):data[f.title.text][-npoints:] for f in figs}
new_data['t'] = data['Time'][-npoints:]*1e3
source.stream(new_data, npoints)
# define HTML layout and behavior
curdoc().add_root(Column(Row(slider_npoints, Column(detector_select, update_detector_button)), grid))
curdoc().add_periodic_callback(update, 500)
कोई भी विचार सर्वर एप्लिकेशन के लिए ऐसा कैसे करना है? सबकुछ स्पष्ट है, लेकिन session.loop_until_closed() बोके सेवा के लिए काम नहीं कर रहा है। –
ऐसा लगता है कि 'loop_until_closed()' उपयोग अब निराश है: https://github.com/bokeh/bokeh/pull/7339 –