Hi,
I have been trying to update editor values for a Tabulator and haven’t been able to figure out even though I have spent six days for testing different kind of solutions to fix this.
Tabulator library has an a javascript example on how to update Tabulator selector values dynamically so I guess it should be possible also on Panel.
After creating a Tabulator I can change editor option values, but new option values don’t get rendered to the table.
Both of the following ways update option values:
table.editors['col1'].options = #list of values for options
table.editors.update(#dictionary of new editor objects)
Below is my full code for trying to figure out how to make this function properly. Is there something wrong with my code that I don’t understand which is causing SelectEditor options not updating on the Tabulator widget after updating the values?
I do appreciate any advice.
class TabuApp(pn.viewable.Viewer):
listofoptions1 = ['A','B','C','D']
listofoptions2 = ['E','T','X','U']
this_class_bokeh_editors = {
'col1': SelectEditor(options=listofoptions1),
'col2': SelectEditor(options=listofoptions1),
'col3': SelectEditor(options=listofoptions1),
}
this_class_other_bokeh_editors = {
'col1': SelectEditor(options=listofoptions2),
'col2': SelectEditor(options=listofoptions2),
'col3': SelectEditor(options=listofoptions2),
}
def __init__(self):
self.df = pd.DataFrame(columns=['col1', 'col2', 'col3'])
self.table = pn.widgets.Tabulator(name ='table', value=self.df, show_index=False)
self.table.editors.update(self.this_class_bokeh_editors)
def __panel__(self):
return self.table
def fill_example_data(self):
self.table.value = createTestDf()
def change_editor_values(self):
self.table.editors.update(self.this_class_other_bokeh_editors)
def add_random_rows(self):
new_df = pd.concat([self.table.value, createDfContent()], axis=0, verify_integrity=True)
self.table._update_data(new_df)
def createTestDf():
df = pd.DataFrame({'col1': ['D', 'Y'],
'col2': ['NY', 'CA'],
'col3': ['SVG', 'DVG']},
index=['XYSJ', 'JDKL'])
return df
def createDfContent():
df = pd.DataFrame({'col1': [giveRandomLetter(1), giveRandomLetter(1)],
'col2': [giveRandomLetter(2), giveRandomLetter(2)],
'col3': [giveRandomLetter(3), giveRandomLetter(3)]},
index=[giveRandomLetter(4), giveRandomLetter(4)])
return df
def giveRandomLetter(length):
letters = 'ABCDEFGHIJKLMNOPQR'
outputstring = str()
for i in range(0,length):
randomvalue = randint(0,len(letters)-1)
letter = letters[randomvalue]
outputstring += letter
return outputstring