I would like to be able to specify Tabulator row colors based on cell values containing hex color strings.
I have tried to bind the table to an updating method and apply a watcher but none of the methods have succeeded.
import pandas as pd
import panel as pn
class App():
def __init__(self):
self.df = pd.DataFrame({'X':[1,2,3],
'color': ['#000000', '#888888', '#ffffff']})
self.table = pn.widgets.Tabulator(name ='sdfsd', value=self.df, show_index=False)
self._init_widget()
def _set_row_color(self, row):
return [f"background-color: {row['color']}"] * len(row)
def _init_widget(self):
self.table = pn.widgets.Tabulator(value=self.df, show_index=False)
def _update_style(self, new_df):
# Triggered by bind, but the new style never takes effect
self.table.style = new_df.style.apply(self._set_row_color, axis=1)
return self.table
class WatchingApp(App):
def _init_widget(self):
super()._init_widget()
self.table.param.watch(self._update_style, ['value'], onlychanged=False)
def _update_style(self, event):
self.table.style = event.new.style.apply(self._set_row_color, axis=1)
#MISSING RE-RENDERING OF THE TABLE HERE!
app = App()
pn.Column(WatchingApp().table,
pn.bind(app._update_style, app.table)).show()