image.png
image.png
from bokeh.layouts import widgetbox
from bokeh.models import Slider
from bokeh.io import curdoc
#Create a slider widget
slider_widget = Slider(start = 0, end = 100, step = 10, title = 'Single Slider')
#Create a layout for the widget
slider_layout = widgetbox(slider_widget)
#Add the slider widget to the application
curdoc().add_root(slider_layout)
$ bokeh serve --show 6_single_slider.py
2018-08-07 22:31:08,152 Starting Bokeh server version 0.13.0 (running on Tornado 5.0.2)
2018-08-07 22:31:08,157 Bokeh app running at: http://localhost:5006/6_single_slider
2018-08-07 22:31:08,157 Starting Bokeh server with process id: 4004
[4014:4042:0807/223108.727386:ERROR:browser_gpu_channel_host_factory.cc(120)] Failed to launch GPU process.
2018-08-07 22:31:08,734 200 GET /6_single_slider (::1) 25.01ms
2018-08-07 22:31:09,235 101 GET /6_single_slider/ws?bokeh-protocol-version=1.0&bokeh-session-id=DIPJXgIOQBG65IwoBU8WsZ2dCevD8Ex0mrEfG9hKs1Gm (::1) 1.09ms
2018-08-07 22:31:09,236 WebSocket connection opened
2018-08-07 22:31:09,236 ServerConnection created
image.png
from bokeh.layouts import widgetbox
from bokeh.models import Slider
from bokeh.io import curdoc
#Create multiple slider widgets
slider_widget1 = Slider(start = 0, end = 100, step = 10, title = 'Slider 1')
slider_widget2 = Slider(start = 0, end = 50, step = 5, title = 'Slider 2')
slider_widget3 = Slider(start = 50, end = 100, step = 5, title = 'Slider 3')
#Create a layout for the widget
slider_layout = widgetbox(slider_widget1, slider_widget2, slider_widget3)
#Add the slider widget to the application
curdoc().add_root(slider_layout)
image.png
from bokeh.models import Slider, ColumnDataSource
from bokeh.io import curdoc
from bokeh.layouts import row
from bokeh.plotting import figure
from numpy.random import random
#Create data for the plot
initial_points = 500
data_points = ColumnDataSource(data = {'x': random(initial_points), 'y': random(initial_points)})
#Create the plot
plot = figure(title = "Random scatter plot generator")
plot.diamond(x = 'x', y = 'y', source = data_points, color = 'red')
#Create the slider widget
slider_widget = Slider(start = 0, end = 10000, step = 10, value = initial_points, title = 'Slide right to increase number of points')
#Define the callback function
def callback(attr, old, new):
points = slider_widget.value
data_points.data = {'x': random(points), 'y': random(points)}
slider_widget.on_change('value', callback)
#Create a layout for the application
layout = row(slider_widget, plot)
#Add the layout to the application
curdoc().add_root(layout)
image.png
image.png
网友评论