How To Get A Bokeh Server To Display A Datatable
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 ac
Solution 1:
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.
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()]]))
Post a Comment for "How To Get A Bokeh Server To Display A Datatable"