Hi,
I need to add TableColumn to a DataTable after the table was created. The column gets added and shown (see the minimal example added).
I am expecting to be able to change the visibility of this new column but when I change the “visible” property nothing happens (The column stays visible at all time).
Could you tell me if it is possible to do? If not is there a workaround?
Minimal Bokeh Server Example:
from bokeh.models import ColumnDataSource
from bokeh.models import DataTable
from bokeh.models import TableColumn
from bokeh.models import NumberFormatter
from bokeh.models import Toggle
from bokeh.layouts import row
from bokeh.plotting import show
from bokeh.io import curdoc
source = ColumnDataSource(data=dict())
columns = {
"name": TableColumn(field="name", title="Employee Name"),
"salary": TableColumn(field="salary", title="Income", formatter=NumberFormatter(format="$0,0.00")),
"years_experience": TableColumn(field="years_experience", title="Experience (years)"),
}
data_table = DataTable(source=source, columns=list(columns.values()), width=800)
toggle1 = Toggle(label='add column')
def cb1(attr, old, new):
if 'test' not in columns:
source.data['test'] = ['test1']
columns['test'] = TableColumn(field="test", title="test")
data_table.columns.append(columns["test"])
toggle1.on_change('active', cb1)
toggle2 = Toggle(label='column visibility')
def cb2(attr, old, new):
if 'test' in columns:
columns['test'].visible = toggle2.active
toggle2.on_change('active', cb2)
layout=row(data_table, toggle1, toggle2)
curdoc().add_root(layout)
curdoc().title = "Data-Table Bokeh Server"
source.data = {
'name' : ['name1'],
'salary' : [20],
'years_experience' : [15],
}
Bokeh Info:
Python version : 3.11.5 | packaged by Anaconda, Inc. | (main, Sep 11 2023, 13:26:23) [MSC v.1916 64 bit (AMD64)]
IPython version : 8.17.2
Tornado version : 6.3.3
Bokeh version : 3.4.1
BokehJS static path : C:\Users\gilles.faure\AppData\Local\miniconda3\envs\EO_py3.11\Lib\site-packages\bokeh\server\static
node.js version : (not installed)
npm version : (not installed)
jupyter_bokeh version : (not installed)
Operating system : Windows-10-10.0.19045-SP0