I have a data table with 40+ columns. I can choose which columns to show in the data table by changing the TableColumn attribute visible to True or False. Here's a small example
filtered_table_data=df[["Date","Li","Be"]]
filtered_table_source= ColumnDataSource(data=filtered_table_data)
filtered_table_cols=[]
filtered_table_cols.append(TableColumn(field='Date', title='Date', width=2000, visible=True))
filtered_table_cols.append(TableColumn(field='Li', title='Li', width=750, visible=False))
filtered_table_cols.append(TableColumn(field='Be', title='Be', width=750,visible=True))
filtered_table=DataTable(source=filtered_table_source, columns=filtered_table_cols)
What I would like to do is use the multi choice widget to be able to choose which columns to show in the data table. For example if only Date and Li is selected then those Table Columns would be set to visible and Be would be set to visible=False. I do not know how to write the callback for that or if I need a customjs callback or just an update function
code so far:
# def update():
# cols=["Date"]+multi_choice.value
# current=df[cols]
filtered_table_data=df[["Date","Li","Be"]]
filtered_table_source= ColumnDataSource(data=filtered_table_data)
filtered_table_cols=[]
filtered_table_cols.append(TableColumn(field='Date', title='Date', width=2000))
filtered_table_cols.append(TableColumn(field='Li', title='Li', width=750,))
filtered_table_cols.append(TableColumn(field='Be', title='Be', width=750))
filtered_table=DataTable(source=filtered_table_source, columns=filtered_table_cols)
multi_choice = MultiChoice(value=["Li", "Be"], options=df.columns[2:-1].tolist(), title='Select elements:')
#multi_choice.on_change("value",lambda attr, old, new: update())
l2=layout([multi_choice, filtered_table])
show(l2)