Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabulator pandas like styles are lost upon resize events #2770

Closed
hyamanieu opened this issue Sep 22, 2021 · 2 comments · Fixed by #2771 or #3156
Closed

Tabulator pandas like styles are lost upon resize events #2770

hyamanieu opened this issue Sep 22, 2021 · 2 comments · Fixed by #2771 or #3156
Labels
type: bug Something isn't correct or isn't working
Milestone

Comments

@hyamanieu
Copy link
Collaborator

ALL software version info

panel 0.12.1 - 0.12.3

Description of expected behavior and the observed behavior

Using styling as detailed in https://panel.holoviz.org/reference/widgets/Tabulator.html#styling works when generating the table.

However it disappears due to either:

  • resizing the window
  • closing or opening the sidebar in a template
  • resizing or moving the layout containing the tabulator.

A current work around is to try to detect any changes and reapply the style. However many events are hard to detect.

This is unrelated to #2695 as I am speaking about the tabulator object itself, not the returned styled HTML from pandas.

Complete, minimal, self-contained example code that reproduces the issue

A reproducible example is in the documentation. Go to https://panel.holoviz.org/reference/widgets/Tabulator.html#styling
then resize your window. The styles disappear and all cells return to a white background and black letters.

@hyamanieu hyamanieu added the TRIAGE Default label for untriaged issues label Sep 22, 2021
@philippjfr philippjfr added type: bug Something isn't correct or isn't working and removed TRIAGE Default label for untriaged issues labels Sep 22, 2021
@philippjfr philippjfr added this to the v0.12.4 milestone Sep 22, 2021
@hyamanieu
Copy link
Collaborator Author

I must reopen: it still happens when changing the "loading" status.

minimal code:

cell 1

import panel as pn
print(pn.__version__)
pn.extension()

import numpy as np
import pandas as pd

style_df = pd.DataFrame(np.random.randn(10, 5), columns=list('ABCDE'))
styled = pn.widgets.Tabulator(style_df, page_size=5)
def color_negative_red(val):
    """
    Takes a scalar and returns a string with
    the css property `'color: red'` for negative
    strings, black otherwise.
    """
    color = 'red' if val < 0 else 'black'
    return 'color: %s' % color

def highlight_max(s):
    '''
    highlight the maximum in a Series yellow.
    '''
    is_max = s == s.max()
    return ['background-color: yellow' if v else '' for v in is_max]

styled.style.applymap(color_negative_red).apply(highlight_max)

styled

Cell 2

styled.loading= True

Cell 3

styled.loading = False

@hyamanieu
Copy link
Collaborator Author

I confirm this now works as expected. Thanks Philipp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't correct or isn't working
Projects
None yet
2 participants