bokeh-server简要说明

2020-06-02  本文已影响0人  NEO_X

可以在python和浏览器中保持"模型对象"之间的同步,就会出现更多额外的强大可能性:

所以,在python和浏览器之间进行同步的功能是Bokeh服务器的主要用途。

Bokeh服务器的适用场景

构建Bokeh应用程序

到目前为止,使用Bokeh服务器创建交互式数据可视化的最灵活方法是创建Bokeh应用程序,并使用Bokeh serve命令为它们提供服务。
在这个场景中,Bokeh服务器使用应用程序代码为所有连接的浏览器创建会话和文档。

[图片上传失败...(image-a94d18-1591083565242)]

Bokeh服务器使用应用程序代码创建Bokeh文档。来自浏览器的每个新连接都会导致Bokeh服务器为该会话创建一个新文档。

一个简单的Bokeh Server的例子

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

#Define the points that create the line plot

x = [1,2,3,4,5,6,7,8,9]
y = [2,3,4,5,6,7,8,9,10]

data_points = ColumnDataSource(data = {'x': x, 'y': y})

plot = figure(title = 'Random Line plot generator')

plot.line('x', 'y', source = data_points, color = 'red')

slider_widget = Slider(start = 0, end = 100, step = 1, value = 10)

def callback(attr, old, new):
    
    points = slider_widget.value
    data_points.data = {'x': random(points), 'y': random(points)}
    
slider_widget.on_change('value', callback)
layout = row(slider_widget, plot)
curdoc().add_root(layout)

使用boker server --show script_name.py 方式调用过程如下


bokeh_server_2.gif
上一篇 下一篇

猜你喜欢

热点阅读