2017-04-23 50 views
0

我可以將DataTable顯示在Jupyter Notebook中,沒有任何問題。但我一直無法通過服務器(curdoc()。add_root())來顯示它。當我嘗試訪問它時,我不會在服務器窗口中看到任何錯誤,並且只是瀏覽器上的空白頁面。我只是看到以下內容:如何讓散景服務器顯示數據表

2017-04-23 16:07:51,188 Starting Bokeh server on port 5006 with applications at paths ['/myapp'] 
2017-04-23 16:07:51,188 Starting Bokeh server with process id: 7484 
2017-04-23 16:07:55,365 200 GET /myapp (172.17.13.2) 188.14ms 
2017-04-23 16:07:55,887 WebSocket connection opened 
2017-04-23 16:07:55,888 ServerConnection created 

下面是服務器正在運行什麼時候在筆記本上它與所需的通話更換,以顯示它(output_notebook(),顯示(佈局)):

import pandas as pd 
from bokeh.plotting import Figure 
from bokeh.models import ColumnDataSource, TextInput, Button, Panel, Tabs, Label, DataTable, TableColumn 
from bokeh.layouts import Row, Column, widgetbox 
from bokeh.io import curdoc, show, output_notebook, gridplot 
from sqlalchemy import create_engine 

engine = create_engine('postgresql+psycopg2://username:[email protected]:5432/dbname') 

def main(): 

    layout = gridplot([[retreive_descriptions()]]) 

    curdoc().add_root(layout) 

def retreive_descriptions(): 
    df = pd.read_sql(sql='SELECT description from public."Description_Categories" WHERE category=\'Unknown\'', con=engine) 

    cds = ColumnDataSource(df) 

    columns = [TableColumn(field='description', title='Description'),TableColumn(field='category', title='Category')] 

    cat_data = DataTable(source=cds, columns=columns, editable=True) 

    return cat_data 

我使用Python 3.4.2和Bokeh Server 0.12.5版。我相當新,所以任何幫助表示讚賞,爲什麼它可能不顯示。

+0

還有我能目前加載了背景虛化服務器上​​正常的數字,沒有任何問題。只是無法顯示DataTable/gridplot。 – Aklys

回答

1

似乎你不能用散景服務器調用主函數中的curdoc函數。 main.py必須在文件末尾有curdoc函數。這工作。從bokeh.models bokeh.plotting導入圖

進口熊貓作爲PD 導入ColumnDataSource,的TextInput,按鈕面板,製表符,標籤,數據表,TableColumn的 從bokeh.layouts導入行,列,widgetbox 從背景虛化.IO進口curdoc,秀,output_notebook,gridplot 從SQLAlchemy的進口create_engine

engine = create_engine('postgresql+psycopg2://username:[email protected]:5432/dbname') 

def retreive_descriptions(): 
    df = pd.read_sql(sql='SELECT description from public."Description_Categories" WHERE category=\'Unknown\'', con=engine) 

    cds = ColumnDataSource(df) 

    columns = [TableColumn(field='description', title='Description'),TableColumn(field='category', title='Category')] 

    cat_data = DataTable(source=cds, columns=columns, editable=True) 

    return cat_data 

curdoc().add_root(gridplot([[retreive_descriptions()]])) 
+0

對,當運行服務器應用程序時,Bokeh服務器不會設置'__name__',因此「主要檢查」將失敗(即不執行)。 'curdoc'不一定要結束,它只是不需要進行主要檢查。 – bigreddot

+0

感謝爲什麼,我仍然得到了一些更好的觀點。到最後,我意味着特定的代碼流。 – Aklys

+0

有可能Bokeh服務器*應該*設置'__name__',但首先需要一些調查。隨時打開一個關於GH的問題來討論:https://github.com/bokeh/bokeh/issues – bigreddot

相關問題