Hi all,
I believe that the table widget, when it contains more than a just a few columns of data, can really slow down a bokeh app. For example, zoom in/out of a webpage can become very slow as can zoom and pan functions on a plot that contains a large table. The number of rows however does not seem to play much of a role. As an example I wrote a small demonstration code.
You can modify if you want it “slow” or “fast”, just see the comments. It produces just a table of numbers and an xy plot of just the first two columns. To see what I am talking about, just try zooming in/out of the webpage and scrolling and zooming on the plot. When only two columns are displayed, (slow_table = False) even with 10,000 rows, the zoom and scroll is pretty much real-time. If you set slow_table = True, then it will display all 30 columns and the webpage and plot zoom starts to hiccup and scrolling on the plot is not very smooth. You can also change the total number of rows and columns to see where performance issues begin. Because the plot is always plotting the same two columns with the same number of data points, it is not the plot slowing down the app, it is the table slowing down the app I believe.
I guess I am just surprised that a static table would cause any performance difference once it is loaded.
I am using Windows 10, and Bokeh 0.12.16, chrome browser
If you have any advice on how to boost performance with tables I would love to hear it. Thanks!
–Collin
···
##############
##############
on windows: To run, in terminal: bokeh serve --allow-websocket-origin=localhost:5005 bokeh_widget_test.py --port 5005
on windows: http://localhost:5005/bokeh_widget_test
###############
###############
from bokeh.plotting import curdoc, figure
from bokeh.io import output_file, show
from bokeh.layouts import widgetbox
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import DataTable, TableColumn
import pandas as pd
from bokeh.layouts import row, column
from bokeh.models import Select
from bokeh.plotting import curdoc
import datetime
import numpy as np
######################
######################
Pick webpage speed you want by using True/False
slow_table = False
######################
######################
######################
######################
slect desired row and column numbers (initially tested with 10000 rows and 30 columns)
row_num = 10000
column_num = 30
######################
######################
todays_date = datetime.datetime.now().date()
index = pd.date_range(todays_date-datetime.timedelta(10), periods=row_num, freq=‘D’)
columns =
x = 0
while x < 30:
columns.append("Dummy%d"%(x))
x+=1
df = pd.DataFrame(index=index, columns=columns)
df = df.fillna(0) # with 0s rather than NaNs
data = np.array([np.arange(row_num)]*column_num).T
df = pd.DataFrame(data, index=index, columns=columns)
output_file(“data_table.html”)
legendHeaders_short = [“Dummy1” ,“Dummy2”]
legendHeaders_long = columns
x = 0
while x < 30:
legendHeaders_long.append("Dummy%d"%(x))
x+=1
columns =
if slow_table == True:
headers = legendHeaders_long
else:
headers = legendHeaders_short
for h in headers:
tc = TableColumn(field=h, title=h, width=300)
columns.append(tc)
source = ColumnDataSource(df)
data_table = DataTable(source=source, columns=columns, width=750, height=280)
tools = ‘pan,wheel_zoom,box_zoom,xbox_select,reset’
fig1 = figure(plot_height=400, plot_width=400, tools=tools)
r =fig1.circle(x = ‘Dummy1’,y = ‘Dummy2’, size=5, source=source, selection_color=“orange”, alpha=0.6, nonselection_alpha=0.1, selection_alpha=0.4)
#setup page
widgets = column(data_table, fig1)
main_row = row(widgets)
home = column(main_row)
curdoc().title = “Table Test”
curdoc().add_root(home)