简体   繁体   English

散景Python:服务器连接错误

[英]Bokeh Python: Server connection error

When running the animated code found in (examples/plotting/server/animated.py), I get the error: 运行(examples / plotting / server / animated.py)中的动画代码时,出现错误:

IOError: Cannot push session document because we failed to connect to the server (to start the server, try the 'bokeh serve' command) IOError:无法推送会话文档,因为我们无法连接到服务器(要启动服务器,请尝试使用“ bokeh serve”命令)

I have read that removing session = push_session(curdoc()) will resolve the issue as users hosting from localhosts do not need that line, however it is not clear what to replace it with? 我已经读到删除session = push_session(curdoc())将解决此问题,因为从本地主机托管的用户不需要该行,但是不清楚用什么替换它?

Code below: 代码如下:

from numpy import pi, cos, sin, linspace, roll

from bokeh.client import push_session
from bokeh.io import curdoc
from bokeh.plotting import figure

M = 5
N = M*10 + 1
r_base = 8
theta = linspace(0, 2*pi, N)
r_x = linspace(0, 6*pi, N-1)
rmin = r_base - cos(r_x) - 1
rmax = r_base + sin(r_x) + 1

colors = ["FFFFCC", "#C7E9B4", "#7FCDBB", "#41B6C4", "#2C7FB8", "#253494", "#2C7FB8", "#41B6C4", "#7FCDBB", "#C7E9B4"] * M

p = figure(x_range=(-11, 11), y_range=(-11, 11))
r = p.annular_wedge(0, 0, rmin, rmax, theta[:-1], theta[1:],
                fill_color=colors, line_color="white")

session = push_session(curdoc())

ds = r.data_source

def update():
    rmin = roll(ds.data["inner_radius"], 1)
    rmax = roll(ds.data["outer_radius"], -1)
    ds.data.update(inner_radius=rmin, outer_radius=rmax)

curdoc().add_periodic_callback(update, 30)

session.show(p) 

session.loop_until_closed() 

It works for me when I start a Bokeh server in the directory with the Python file with 当我使用Python文件在目录中启动Bokeh服务器时,它对我有用

bokeh serve

and then open a new terminal and execute the Python file with 然后打开一个新的终端并使用以下命令执行Python文件

python animated.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM