diff --git a/panel/pane/markup.py b/panel/pane/markup.py index e82c32b24b..ad8ce7a8d4 100644 --- a/panel/pane/markup.py +++ b/panel/pane/markup.py @@ -173,7 +173,7 @@ def applies(cls, obj): module = getattr(obj, '__module__', '') name = type(obj).__name__ if (any(m in module for m in ('pandas', 'dask', 'streamz')) and - name in ('DataFrame', 'Series', 'Random', 'DataFrames', 'Seriess')): + name in ('DataFrame', 'Series', 'Random', 'DataFrames', 'Seriess', 'Styler')): return 0.3 else: return False @@ -215,6 +215,9 @@ def _get_properties(self): if hasattr(df, 'to_html'): if 'dask' in module: html = df.to_html(max_rows=self.max_rows).replace('border="1"', '') + elif 'style' in module: + classes = ' '.join(self.classes) + html = df.to_html(table_attributes=f'class="{classes}"') else: kwargs = {p: getattr(self, p) for p in self._rerender_params if p not in DivPaneBase.param and p != '_object'} diff --git a/panel/widgets/tables.py b/panel/widgets/tables.py index f56450195b..3fd7fe4d42 100644 --- a/panel/widgets/tables.py +++ b/panel/widgets/tables.py @@ -915,6 +915,12 @@ class Tabulator(BaseTable): } def __init__(self, value=None, **params): + import pandas as pd + if isinstance(value, pd.io.formats.style.Styler): + style = value + value = value.data + else: + style = None configuration = params.pop('configuration', {}) self.style = None self._computed_styler = None @@ -924,6 +930,8 @@ def __init__(self, value=None, **params): super().__init__(value=value, **params) self._configuration = configuration self.param.watch(self._update_children, self._content_params) + if style is not None: + self.style._todo = style._todo def _validate(self, *events): super()._validate(*events) @@ -1533,4 +1541,3 @@ def on_button_click(self, callback, column=None): if column not in self._on_click_callbacks: self._on_click_callbacks[column] = [] self._on_click_callbacks[column].append(callback) -