-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
Is your feature request related to a problem? Please describe.
I am trying to use a CheckboxButtonGroup widget to toggle the visibility of columns in a DataTable. My approach to this is to use some CustomJS that adds or removes columns from the table in question upon clicking the button:
# example.py
from datetime import date
from random import randint
from bokeh.io import show
from bokeh.layouts import column
from bokeh.models import (
ColumnDataSource,
DataTable,
DateFormatter,
TableColumn,
CheckboxButtonGroup,
CustomJS
)
from bokeh.plotting import curdoc
data = dict(
dates=[date(2014, 3, i+1) for i in range(10)],
downloads=[randint(0, 100) for i in range(10)],
)
source = ColumnDataSource(data)
columns = [
TableColumn(field="dates", title="Date", formatter=DateFormatter()),
TableColumn(field="downloads", title="Downloads"),
]
data_table = DataTable(source=source, columns=columns, width=400, height=280)
column_choice = CheckboxButtonGroup(
labels=[
"Date",
"Downloads"
],
active=[0, 1],
)
column_choice.js_on_click(
CustomJS(
args=dict(
table=data_table, columns=columns
),
code="""
var visible_columns = []
for (var i = 0; i < this.active.length; i++) {
visible_columns.push(columns[this.active[i]])
}
table.columns = visible_columns;
""",
)
)
curdoc().add_root(column(column_choice, data_table))$ bokeh serve --show example.py
This works fine, and the table responds as expected. However, I get serialization errors in console every time I click the button - I reported this bug in #11422.
Describe the solution you'd like
An alternative method to toggle column visibility would be to have a visible property on TableColumns, similar to the one for DataTables. This would allow me to toggle the visibility of the columns using this property, which would be simpler than what I am currently doing and would potentially circumvent the serialization errors I encountered in #11422.
Describe alternatives you've considered
An alternative suggested by @bryevdv to try and avoid the serialization errors was to use a hidden DataTable in the document as a "bank" for the columns I want to toggle on and off for the main table. I tried this approach out but encountered the same serialization errors.
Additional context
This issue came up while working on dask/distributed#4614.