Does anyone have an example of how to run python code in jupyter by clicking a button in Bokeh?
-
documentationOpen AI - Opting Out– Open AI - Opting Out2015-09-05 21:59:46 +00:00Commented Sep 5, 2015 at 21:59
-
This is similar to what i am trying to accomplish but related to select items and much more involved: github.com/bokeh/bokeh/blob/master/examples/app/stock_applet/…Chuck– Chuck2015-09-05 22:24:16 +00:00Commented Sep 5, 2015 at 22:24
-
The answer here is great. You should accept it if you feel it has answered your question.ryanjdillon– ryanjdillon2016-10-25 17:37:52 +00:00Commented Oct 25, 2016 at 17:37
Add a comment
|
1 Answer
UPDATE The original answer was very out of date. The answer has been updated to reflect changes since Bokeh 0.11 which was released in January of 2016.
A complete example pared from the sliders demo, that uses features from Bokeh 0.12.4:
from numpy import linspace, pi, sin
from bokeh.io import curdoc
from bokeh.layouts import row, widgetbox
from bokeh.models import ColumnDataSource, Slider
from bokeh.plotting import figure
# Set up data
x = linspace(0, 4*pi, 200)
y = sin(x)
source = ColumnDataSource(data=dict(x=x, y=y))
# Set up plot
plot = figure(x_range=(0, 4*pi), y_range=(-2.5, 2.5))
plot.line('x', 'y', source=source, line_width=3, line_alpha=0.6)
# Set up widgets
amplitude = Slider(title="amplitude", value=1.0, start=-5.0, end=5.0)
freq = Slider(title="frequency", value=1.0, start=0.1, end=5.1)
# Set up callbacks
def update(attrname, old, new):
# Get the current slider values
a = amplitude.value
k = freq.value
# Update the data for the new curve
source.data = dict(x=x, y=a*sin(k*x))
amplitude.on_change('value', update)
freq.on_change('value', update)
# Set up layout and add to document
inputs = widgetbox(amplitude, freq)
curdoc().add_root(row(inputs, plot, width=1200))
Run with bokeh serve --show <filename> and get the following responsive web app in your browser:
7 Comments
Chuck
This was really helpful. I appreciate it.
mdurant
Note that the new version of bokeh-server should make this easier/nicer, but I haven't played with it yet.
J'e
any change we can get an update? bokeh-server was removed after version 0.10.
mdurant
Looks like thorough documentation here bokeh.pydata.org/en/latest/docs/user_guide/server.html
bigreddot
Updated to reflect current
bokeh serve in use since January 2016 (Bokeh 0.11 and newer) |
