Please take a moment to search the forum and documentation before posting a new topic.
If you’re creating a debugging post, please include the following info:
- Are you running your app locally or is it deployed?
Locally, using MS Edge browser
MWE below
import pandas as pd
import streamlit as st
df = pd.DataFrame({'A':[1,2,3,4], 'B':['a','b','c','d'], 'C':['foo','bar','qux', 'baz']})
def apply_style(df, fixed_cols, required_cols):
styles = pd.DataFrame('', index=df.index, columns=df.columns)
for col in df.columns:
for idx in df.index:
if col in fixed_cols:
styles.loc[idx,col] = 'background-color: lightgrey'
elif col in required_cols:
styles.loc[idx,col] = 'background-color: lightsalmon'
else:
styles.loc[idx,col] = ''
print(styles)
return styles
df_styled = df.style.apply(lambda df: apply_style(df, ['A'], ['C']), axis=None)
st.data_editor(
df_styled,
hide_index=True,
column_config={'C': st.column_config.TextColumn('C', required=True)},
disabled=('A'),
num_rows='dynamic'
)
There is no error message or warning. Column C is not being coloured, but column A is.
When the application is stopped, column C colouring is rendered.
Appreciate any advice on this, thank you
- Share the Streamlit and Python versions.
python - 3.12
streamlit - 1.45.0
pandas - 2.2.3