python - Configure Blaze and start Bokeh server from Pyramid web-application -


i have pyramid web-application on customer ability plot large data sets interactively.

the application displays sub-set of customer's selected data zoom, pan, hover, etc. capabilities using d3. however, in case user needs see full set same functionality, use bokeh server , use down-sampling.

where running trouble down-sampling function can used plots employing serverdatasource.

ideally, bokeh server running , push customer's selected data , use source down-sampled plot. however, far can tell, blaze doesn't allow me push data existing server.

instead, thought when user requested plot, use 1 of pyramid's views modify blaze configuration file , start bokeh server.

@view_config(route_name='startbokehserver', renderer = 'json',permission='view') def startbokehserver_view(request):      r"""      configures blaze_config.py file create dict containing customer's select reversal data     starts bokeh server using modified blaze_config.py file @ http://localhost:5006      """     bokeh_server.run() 

once data stored on server, view plot curve bokeh server data source.

@view_config(route_name='fetchplotdatarev', renderer = 'json',permission='view') def fetchplotdatarev_view(request):    r"""    plots full reversal data using bokeh's down-sampling method.    """     bokeh.plotting import output_server, figure, show     bokeh.models import hovertool, range1d     bokeh.transforms import line_downsample            output_server("full reversal curve(s)")     c=bokeh_client('http://localhost:5006')     d=bokeh_data(c)      rev=d.rev      source=line_downsample.source()     source.from_blaze(rev,local=true)      tools="pan,wheel_zoom,box_zoom,reset,hover"     p = figure(title="reversal tooltip", tools=tools)      p1=p.scatter(x='time',y='aa_cd',color='#0000ff',source=source)     p1.select(dict(type=hovertool)).tooltips=[("(x,y)", "($x, $y)"),]      p2=p.scatter(x='time',y='aa_cv',color='#ff0000',source=source)     p2.select(dict(type=hovertool)).tooltips=[("(x,y)", "($x, $y)"),]      xmin=float(rev.time.min())     xmax=float(rev.time.max())     ymin=float(rev.aa_cv.min())     ymax=float(rev.aa_cd.max())      p.x_range=range1d(start=xmin,end=xmax)     p.y_range=range1d(start=ymin,end=ymax)              show(p) 

finally, signal javascript bokeh server window has been closed posts request view stop server.

@view_config(route_name='stopbokehserver', renderer = 'json',permission='view') def stopbokehserver_view(request):      r"""      stops bokeh server.      """     bokeh_server.start.stop() 

however, application exits status 2 when trying serve /startbokehserver. traceback included below.

usage: pserve [-h] [--ip ip] [--port port] [--url-prefix url_prefix]       [-d blaze_config] [-m] [--script script] [--backend backend]       [--redis-port redis_port] [--start-redis] [--no-start-redis]       [--ws-conn-string ws_conn_string] [-d] [--dev] [--filter-logs]       [-j] [-s] [--robust-reload] [-v] pserve: error: unrecognized arguments: development.ini /home/katmeg/mat-cruncher/pyramidanalysis 2015-04-09 12:20:53,730 error [waitress][dummy-11] exception when serving /startbokehserver traceback (most recent call last):   file "/usr/local/lib/python2.7/dist-packages/waitress-0.8.9-py2.7.egg/waitress/channel.py", line 337, in service task.service()   file "/usr/local/lib/python2.7/dist-packages/waitress-0.8.9-py2.7.egg/waitress/task.py", line 173, in service self.execute()   file "/usr/local/lib/python2.7/dist-packages/waitress-0.8.9-py2.7.egg/waitress/task.py", line 392, in execute app_iter = self.channel.server.application(env, start_response)   file "/usr/local/lib/python2.7/dist-packages/pyramid-1.5.1-py2.7.egg/pyramid/router.py", line 242, in __call__ response = self.invoke_subrequest(request, use_tweens=true)   file "/usr/local/lib/python2.7/dist-packages/pyramid-1.5.1-py2.7.egg/pyramid/router.py", line 217, in invoke_subrequest response = handle_request(request)   file "/usr/local/lib/python2.7/dist-packages/pyramid_debugtoolbar-2.3-py2.7.egg/pyramid_debugtoolbar/toolbar.py", line 178, in toolbar_tween response = _handler(request)   file "/usr/local/lib/python2.7/dist-packages/pyramid_debugtoolbar-2.3-py2.7.egg/pyramid_debugtoolbar/panels/performance.py", line 57, in resource_timer_handler result = handler(request)   file "/usr/local/lib/python2.7/dist-packages/pyramid-1.5.1-py2.7.egg/pyramid/tweens.py", line 21, in excview_tween response = handler(request)   file "/usr/local/lib/python2.7/dist-packages/pyramid-1.5.1-py2.7.egg/pyramid/router.py", line 163, in handle_request response = view_callable(context, request)   file "/usr/local/lib/python2.7/dist-packages/pyramid-1.5.1-py2.7.egg/pyramid/config/views.py", line 245, in _secured_view return view(context, request)   file "/usr/local/lib/python2.7/dist-packages/pyramid-1.5.1-py2.7.egg/pyramid/config/views.py", line 355, in rendered_view result = view(context, request)   file "/usr/local/lib/python2.7/dist-packages/pyramid-1.5.1-py2.7.egg/pyramid/config/views.py", line 501, in _requestonly_view response = view(request)   file "/home/katmeg/mat-cruncher/pyramidanalysis/pyramidanalysis/views.py", line 649, in startbokehserver_view bokeh_server.run()   file "/home/katmeg/pyrenv/local/lib/python2.7/site-packages/bokeh/server/__init__.py", line 134, in run args = parser.parse_args(sys.argv[1:])   file "/usr/lib/python2.7/argparse.py", line 1691, in parse_args self.error(msg % ' '.join(argv))   file "/usr/lib/python2.7/argparse.py", line 2347, in error self.exit(2, _('%s: error: %s\n') % (self.prog, message))   file "/usr/lib/python2.7/argparse.py", line 2335, in exit _sys.exit(status) systemexit: 2 

note: plots work intend them when run bokeh-server executable command line , create , serve them separate python script.

so questions follows: can push data running bokeh server , use data source down-sampling? , if not, how can start/stop bokeh server requested within pyramid application?

thanks in advance help!

here how application dynamically configures server data source, starts bokeh server, , plots requested data on the bokeh server customer navigate.

the data plotted passed startbokehserver view written temporary text file. bokeh server started using python's subprocess , configuration file reads text file , configures data such can read blaze.

views.py

@view_config(route_name='startbokehserver',renderer = 'json',permission='view') def startbokehserver_view(request):      # plotdatarev dictionary containing data requested web page     open('pyramidanalysis/temp/reversal_data.txt','wb') handle:       pickle.dump(plotdatarev,handle)       bokeh_pid=str(subprocess.popen(['/bokeh-server','-d','blaze_config.py'],stdout=subprocess.pipe).pid)     request.session['bokehpid']=bokeh_pid 

blaze_config.py

import pandas pd import pickle  open('pyramidanalysis/temp/reversal_data.txt','rb') handle:   b=pickle.loads(handle.read())  data=dict()  keys=b.keys() key in keys:   data[key]=pd.dataframe(b[key]) 

the server page displayed in iframe on web-page , closing frame or main window initiates view terminates bokeh server , deletes temporary text file.


Popular posts from this blog