为什么 运行 散景服务器显示空白页面?

Why does a running bokeh server display an empty page?

我正在尝试重现 Metthew Rocklin blogpost 的第一个示例。

关于如何 运行 Bokeh 服务器的描述很全面,但我仍然无法使其正常工作。我正在 运行 使用命令 "bokeh serve big_bokeh_test.py --show":

在 windows shell 上执行以下脚本
from bokeh.server.server import Server
from bokeh.application import Application
from bokeh.application.handlers.function import FunctionHandler
from bokeh.plotting import figure, ColumnDataSource

def make_document(doc):
    fig = figure(title='Line plot!', sizing_mode='scale_width')
    fig.line(x=[1, 2, 3], y=[1, 4, 9])

    doc.title = "Hello, world!"
    doc.add_root(fig)

apps = {'/': Application(FunctionHandler(make_document))}

server = Server(apps, port=5000)
server.start()

没有错误,服务器正在 运行ning,只是输出是一个空页面。我已经在寻找解决方案。以下链接可能相关但没有解决我的问题:

Bokeh Server not displaying plots

我正在使用 Python 3.6.3(64 位)和散景 0.12.9。这是 windows shell:

的输出
PS C:\Users\kateryna.smirnova\Documents\IBB\bokeh_graphs> bokeh serve big_bokeh_test.py --show
2017-10-14 10:48:00,231 Starting Bokeh server version 0.12.9 (running on Tornado 4.5.2)
2017-10-14 10:48:00,235 Bokeh app running at: http://localhost:5006/big_bokeh_test
2017-10-14 10:48:00,235 Starting Bokeh server with process id: 564
2017-10-14 10:48:00,445 Starting Bokeh server version 0.12.9 (running on Tornado 4.5.2)
2017-10-14 10:48:00,469 200 GET /big_bokeh_test (::1) 137.37ms
2017-10-14 10:48:00,785 101 GET /big_bokeh_test/ws?bokeh-protocol-version=1.0&bokeh-session-id=ERMj5xsMHtF7o3P6KxRRrPDfIMAvIhMcNffgxuct4950 (::1) 1.03ms
2017-10-14 10:48:00,786 WebSocket connection opened
2017-10-14 10:48:00,788 ServerConnection created

你运行和

一起做这个吗
bokeh serve script.py

?如果是这样,那对于这种用法是不正确的。这种带有显式 ServerApplication 的用法 m 用于以编程方式嵌入 Bokeh 服务器,因此可以 运行 如:

python script.py

当我运行那样时,脚本立即存在,无法建立任何连接。我希望从代码中得到这一点。如果您希望脚本 运行 并持续服务,您需要通过将此放在脚本末尾来启动 Tornado ioloop

server.io_loop.start()

当我这样做时,我可以打开一个连接,并查看情节。

或者,如果你想要 运行 东西 bokeh serve 风格,那么你根本不需要任何 ServerApplication 位,但你do 需要使用 add_root 将情节添加到 curdoc(这就是为什么什么都没有显示的原因,除非你将内容添加到 curdoc,你是提供一个空文档)。这是 运行 bokeh serve:

的完整代码示例
from bokeh.io import curdoc
from bokeh.plotting import figure, ColumnDataSource

fig = figure(title='Line plot!', sizing_mode='scale_width')
fig.line(x=[1, 2, 3], y=[1, 4, 9])

curdoc().title = "Hello, world!"
curdoc().add_root(fig)

用户指南的 Running a Bokeh Server 部分描述了大部分内容。