Summary
having a dataframe that i want to display its result using st.expander
widget based on the value of column type i want to styled the header of the expander.
the problem is :it doesn’t display the correct result where all the selected record will be displayed with the same style even if the df[‘type’] is different
Code snippet:
cols = st.columns(len(df))
for i ,x in enumerate(cols):
if df[i]['type'] == 'employee':
font_css ='''
<style>
.streamlit-expanderHeader.st-ae.st-dj.st-ag.st-ah.st-ai.st-aj.st-bv.st-dk.st-bw.st-dl.st-dm.st-dn.st-do.st-ar.st-as.st-dp.st-dq.st-b3.st-cj.st-c5.st-dr.st-b4.st-ds.st-c3.st-c4.st-c2.st-c1{
font-size:30px;
text-align:center;
color:yellow;
background-color :red;
}
</style>
'''
st.write(font_css,unsafe_allow_html = True)
if df[i]['type'] == 'supervisor':
font_css ='''
<style>
.streamlit-expanderHeader.st-ae.st-dj.st-ag.st-ah.st-ai.st-aj.st-bv.st-dk.st-bw.st-dl.st-dm.st-dn.st-do.st-ar.st-as.st-dp.st-dq.st-b3.st-cj.st-c5.st-dr.st-b4.st-ds.st-c3.st-c4.st-c2.st-c1{
font-size:30px;
text-align:center;
color:Green;
}
</style>
'''
st.write(font_css,unsafe_allow_html = True)
if df[i]['type'] == 'CEO':
font_css ='''
<style>
.streamlit-expanderHeader.st-ae.st-dj.st-ag.st-ah.st-ai.st-aj.st-bv.st-dk.st-bw.st-dl.st-dm.st-dn.st-do.st-ar.st-as.st-dp.st-dq.st-b3.st-cj.st-c5.st-dr.st-b4.st-ds.st-c3.st-c4.st-c2.st-c1{
font-size:30px;
text-align:center;
color:blue;
background-color :red;
}
</style>
'''
st.write(font_css,unsafe_allow_html = True)
with st.expander(f"{df[i]['name']}"):
st.image(df[i][f'ImgPath'],width=100)
If applicable, please provide the steps we should take to reproduce the error or specified behavior.
Expected behavior:
the code must display multiple expanders
color:yellow; background-color :red; if type == employe
color:Green; if type == supervisor
color:blue;background-color :red; if type == ceo
Actual behavior:
Explain the undesired behavior or error you see when you run the code above.
If you’re seeing an error message, share the full contents of the error message here.
Debug info
- Streamlit version: 1.13
- Python version:3.10
- Using PipEnv
- OS version: windows 10
- Browser version: chrome 106