如何获取Bokeh服务器以显示数据表 [英] How to get a Bokeh Server to display a DataTable

查看:59
本文介绍了如何获取Bokeh服务器以显示数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以毫无问题地将数据表显示在Jupyter Notebook中.但是我还无法通过服务器(curdoc().add_root())来显示它.当我尝试访问它时,在服务器窗口中没有任何错误,在浏览器上只有空白页.我只看到以下内容:

I can get the DataTable to display in a Jupyter Notebook without any issues. But i haven't been able to get it to display via the Server (curdoc().add_root()). When I attempt to access it I don't get any errors in the server window and just a blank page on the browser. I just see the following:

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(),show(layout)):

Below is what the server is running and when in the notebook it's replaced with the required calls to display it (output_notebook(), show(layout)):

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:password@domain.local: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.我对此还很陌生,因此感谢您对任何可能无法显示的帮助.

I'm using Python 3.4.2 and Bokeh Server version 0.12.5. I'm fairly new to this so any help is appreciated with why it might not be displaying.

推荐答案

似乎您无法使用bokeh服务器在主函数内调用curdoc函数. main.py必须在文件末尾具有curdoc函数.这行得通.

Seems you can't call the curdoc function inside the main function with the bokeh server. The main.py has to have curdoc function right at the end of the file. This worked.

将熊猫作为pd导入 从bokeh.plotting导入图 从bokeh.models导入ColumnDataSource,TextInput,Button,Panel,Tabs,Label,DataTable,TableColumn 从bokeh.layouts导入行,列,小部件框 从bokeh.io导入curdoc,show,output_notebook,gridplot 从sqlalchemy导入create_engine

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:password@domain.local: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()]]))

这篇关于如何获取Bokeh服务器以显示数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆