Why does a running bokeh server display an empty page?

无人久伴 提交于 2020-01-23 03:25:08

问题


I am trying to reproduce the very first example from Metthew Rocklin blogpost.

The description on how to run a Bokeh server is comprehensive, but I still cannot get it working. I am running the following script on the windows shell with command "bokeh serve big_bokeh_test.py --show":

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()

There is no error and the server is running, only that the output is an empty page. I have searched for a solution. The following links may be related but did not solve my problem:

How to get a Bokeh Server to display a DataTable

Bokeh Server not displaying plots

bokeh serve running but can't access with browser

I am using Python 3.6.3 (64bit) and bokeh 0.12.9. And here is the output from the 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

回答1:


Are you running this with

bokeh serve script.py

? If so, that is not correct for this style of usage. This style of usage m with explicit Server and Application is for embedding a Bokeh server programmatically, so that things can be run like:

python script.py

When I run it like that, the script exists immediately, and no connections can be made. I would expect this from the code. If you want the script to run and serve continuously, you need to start the Tornado ioloop by putting this at the end of the script:

server.io_loop.start()

When I do this, I can open a connection, and see the plot.

Alternatively, if you want to run things bokeh serve style, then you don't need any of the Server or Application bits at all, but you do need to add the plot to curdoc with add_root (this is why nothing is showing up, unless you add things to curdoc, you are serving an an empty document). Here is a full code sample for running with 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)

Much of this is described in the Running a Bokeh Server setion of the User's Guide.



来源:https://stackoverflow.com/questions/46754417/why-does-a-running-bokeh-server-display-an-empty-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!