Pandas styler with custom style

Hello,

I want to show below dataframe styler using st.dataframe but it is not showing the custom style as per given in make_bar_style, Your inputs will be valuable:

import pandas as pd
import streamlit as st

# example multi-index dataframe
data = {'level_0': [1, 2, 3],
        'level_1': ['A', 'B', 'C'],
        '01/23/2023': ['20%', '30%', '40%'],
        '01/24/2023': ['10%', '20%', '30%'],
        '01/25/2023': ['15%', '25%', '35%'],
        '01/26/2023': ['5%', '10%', '15%'],
        '01/27/2023': ['1%', '2%', '3%']}

df = pd.DataFrame(data)
df = df.set_index(['level_0', 'level_1'])

def make_bar_style(x):
    if '%' in str(x):
        x = float(x.strip('%'))
        return f"background: linear-gradient(90deg,#5fba7d {x}%, transparent {x}%); width: 10em"  
    return ''


st.dataframe(df.style.applymap(make_bar_style))

Thanks,
Nilesh

Hi @Nilesh_Dalvi ,

This should work with st.table but not with st.dataframe. st.dataframe supports pandas styler but only background color, font color & display value. The reason is because st.dataframe uses HTML canvas and thus won’t likely be able to support this (won’t have access to the html dom with HTML canvas).

Hi @willhuang - Thanks for this, st.table is working.