2017-10-15 99 views
1

我想重現Metthew Rocklin blogpost的第一個例子。爲什麼正在運行的散景服務器顯示空白頁面?

有關如何運行Bokeh服務器的說明很全面,但我仍然無法使其工作。我運行下面的腳本在窗戶命令外殼「背景虛化的服務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() 

沒有錯誤,服務器在運行,只是輸出是一個空的頁面。我已經尋找解決方案。下面的鏈接可能相關,但並沒有解決我的問題:

How to get a Bokeh Server to display a DataTable

Bokeh Server not displaying plots

bokeh serve running but can't access with browser

我使用Python 3.6.3(64位)和背景虛化0.12.9。這裏是從Windows外殼程序的輸出:

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 

回答

0

你跟

bokeh serve script.py 

運行呢?如果是這樣,那麼這種用法是不正確的。用法米,明確ServerApplication這種風格是嵌入背景虛化服務器編程,讓事情可以像運行:

python script.py 

當我運行它這樣,劇本立即存在,並沒有連接可以是製作。我希望從代碼中得到這個結果。如果您希望腳本運行,並不斷服務,你需要把這個在腳本的末尾開始龍捲風ioloop

server.io_loop.start() 

當我這樣做,我可以打開一個連接,看劇情。

另外,如果你想運行的東西bokeh serve風格,那麼你不需要任何的ServerApplication位中的全部,但你需要的情節與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相間螺旋纏繞製成的用戶指南的說明。

+0

我正在使用帶有add_root的curdoc,這對我來說效果很好。謝謝bigreddot。 – kateryna

相關問題