This is my first post here, so apologies if it’s missing any info needed.
I am showing a few dataframes with stocks earnings data I previously capture during the day. After querying my DB I need some of this data colour formatted so that I visually identify interesting names. I did this with a pandas styler and applied it to the dataframe, calling the styler with st.write(dataframe). Next step was to add a tick column so that i could select the interesting names and sort the dataframe by this column. For this, the best way I found in the documentation was to create a ‘check’ column in the dataframe and then call the styler with st.data_editor like this:
st.data_editor(best_earnings_styler,
column_config={'check': st.column_config.CheckboxColumn(
'Select',
help='Select stocks',
default=False,
)}
)
Now, my issue is that st.data_editor is not processing styler colour configuration, when st.write or the st.dataframe where behaving correctly.
Debugging data:
I am running the app locally, there is no error message, it simply doesn’t accept the colors style, and this is my full code:
# Code to format best stock earnings
if st.checkbox('Show best earnings'):
# Convert columns to numeric type before applying formatting
best_earnings_df['EPS_chg'] = pd.to_numeric(best_earnings_df['EPS_chg'], errors='coerce')
best_earnings_df['Rev_chg'] = pd.to_numeric(best_earnings_df['Rev_chg'], errors='coerce')
best_earnings_df['EPS_surprise'] = pd.to_numeric(best_earnings_df['EPS_surprise'], errors='coerce')
best_earnings_df['Rev_surprise'] = pd.to_numeric(best_earnings_df['Rev_surprise'], errors='coerce')
best_earnings_df['Avg_volume'] = pd.to_numeric(best_earnings_df['Avg_volume'], errors='coerce')
best_earnings_df['check'] = False
best_earnings_styler = best_earnings_df.style.applymap(color_negative_red, subset=['EPS_chg','EPS_surprise', 'Rev_chg', 'Rev_surprise'])\
.apply (background_gradient,
subset=['EPS_chg'],
m=best_earnings_df['EPS_chg'].min(),
M=best_earnings_df['EPS_chg'].max(),
cmap=custom_cmap)\
.apply (background_gradient,
subset=['EPS_surprise'],
m=best_earnings_df['EPS_surprise'].min(),
M=best_earnings_df['EPS_surprise'].max(),
cmap=custom_cmap)\
.apply (background_gradient,
subset=['Rev_chg'],
m=best_earnings_df['Rev_chg'].min(),
M=best_earnings_df['Rev_chg'].max(),
cmap=custom_cmap)\
.apply (background_gradient,
subset=['Rev_surprise'],
m=best_earnings_df['Rev_surprise'].min(),
M=best_earnings_df['Rev_surprise'].max(),
cmap=custom_cmap)\
.format("{:.2f}", subset=['EPS_chg', 'EPS_surprise','Rev_chg','Rev_surprise'])\
.format("{:,.0f}", subset=['Avg_volume'])
st.data_editor(
best_earnings_styler,
column_config={'check': st.column_config.CheckboxColumn(
'Select',
help='Select stocks',
default=False,
)}
)