Given the following:
import numpy as np
import pandas as pd
import panel as pn
pn.extension('tabulator')
style_df = pd.DataFrame(np.random.randn(4, 5), columns=list('ABCDE'))
styled = pn.widgets.Tabulator(style_df)
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.servable()
panel serve app.py
There is console output:
(<function Styler.applymap.<locals>.<lambda> at 0x7f2a36c7bbe0>, (<function color_negative_red at 0x7f2a36c7bac0>, None), {})
(<function Styler.apply.<locals>.<lambda> at 0x7f2a36c7bc70>, (<function highlight_max at 0x7f2a36c7bb50>, 0, None), {})
This is annoying when I have an app that is applying a lot of styling in different places, then that’s all I see in the console.