python - Make bokeh charts with interactive controls in django -
i have django application uses embedded bokeh visualizations.
right using bokeh.embed.components
function , template like:
<body> {{the_div|safe}} {{the_script|safe}} </body>
thanks this stackoverflow question.
the thing need create more interactive visualizations, adding sliders, checkboxes , other controls.
this example looks want, except couple of issues:
- i don't know how embed kind of object inside django. this way go, perhaps it's not.
- i'm little bit confused having use bokeh-server this. isn't there easy-to-use pure javascript solution?
so, summarizing, know standard approach create dynamic chart interactions using django , bokeh.
there 2 use cases:
without server
if can perform updates in js (don't need call actual python code), easy add interactions using customjs callbacks. there lots of examples @ link, basic simple code sample looks like:
from bokeh.io import vform bokeh.models import customjs, columndatasource, slider bokeh.plotting import figure, output_file, show output_file("callback.html") x = [x*0.005 x in range(0, 200)] y = x source = columndatasource(data=dict(x=x, y=y)) plot = figure(plot_width=400, plot_height=400) plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6) callback = customjs(args=dict(source=source), code=""" var data = source.get('data'); var f = cb_obj.get('value') x = data['x'] y = data['y'] (i = 0; < x.length; i++) { y[i] = math.pow(x[i], f) } source.trigger('change'); """) slider = slider(start=0.1, end=4, value=1, step=.1, title="power", callback=callback) layout = vform(slider, plot) show(layout)
that create standalone html document bokeh plot , slider, updates plot in reaction slider, no need server (i.e. email or serve on static page , work).
with server
if want widgets, interactions, etc. drive actual python code (e.g. scikit-learn, or pandas) need use bokeh server. happily new server of version 0.11
more robust, performant, scalable, , simple use. can see several live deployed bokeh applications (with links source code) here:
as extensive documentation various kinds of deployments in documentation here:
http://bokeh.pydata.org/en/0.11.1/docs/user_guide/server.html
Comments
Post a Comment