Summary
Build a streamlit that display the results from dataframe inside expandables , where the expandables are styled based on the value of the column ‘position’.
Steps to reproduce
Code snippet:
import streamlit as st
import pandas as pd
# Create a dataframe
df = pd.DataFrame({
"name": ["John Doe", "Jane Doe", "Peter Smith"],
"position": ["CEO", "Boss", "Employee"],
"salary": [100000, 50000, 30000]
})
# Define the style of the expandables
def style_expandable(position):
if position == "CEO":
return {"color": "red", "font-weight": "bold"}
elif position == "Boss":
return {"color": "blue", "font-weight": "bold"}
else:
return {"color": "black", "font-weight": "normal"}
# Create the expandables
for i, row in df.iterrows():
with st.expander(row["name"], expanded=False, style=style_expandable(row["position"])):
st.text_input("Name:", row["name"])
st.text_input("Position:", row["position"])
st.text_input("Salary:", row["salary"])
Expected behavior:
Display 3 expandables where each one has different style based on the value of position column.
- Streamlit version: 1.25
- Python version: 3.10
- Using Conda? PipEnv? PyEnv? Pex?
- OS version: windows 10