iam using st.data_editor to create a interactive dataframe, but in my dataframe cells in “Status” column has background color (green or red) based on the value of that cell.
so when u try to update any other columns of my dataframe using st.data_editor the updated value is not visible in the dataframe, i even tried disabling edit option on the “Status” column
If applicable, please provide the steps we should take to reproduce the error or specified behavior.
Expected behavior:
To display the updated value in the UI
Actual behavior:
its not displaying or updating the dataframe with the updated value
in the above given screenshot u can see that status column has a background color and its not editable but notification column is editable but when i try to edit the notification its not getting updated
Hey, I’m having the same issue - seems like data_editor doesn’t really work with styled dataframes which is a bit of a shame as you have to choose one or the other. Hopefully this is something that can be fixed in the next release?
The current version of st.data_editor should be partly compatible with Pandas styler as input, but there are restrictions:
Only works for non-editable / disabled columns.
Currently, it returns the edited data as a dataframe and not as Pandas Styler. So you have to apply the styling logic again on the edited df if you want to show that.
But your issue sounds like something that also might be a bug. Maybe what could help is a video that showcases the editing issue.
On the left, the input is simply the dataframe. On the right, some styling is applied and a pandas styler is handed over to st.data_editor. Editing works perfectly well in the left, but does not work on the right.
Thanks so much for the short, executable example! I was able to make a recording to share so everyone can see what we’re talking about here:
I also removed the styling from column A, but it still failed to commit edits. If I write session state above and below the editor, I can see the edit display in session state before the widget, but it resets when it re-renders the data editor.
I believe this issue distills down to how Streamlit determines equivalency of pandas styler objects. As a workaround, put your styler object into session state and pass it into the data editor from session state. If you don’t redefine your styler with each rerun, it seems to avoid the issue. I’ve modified your code here to demonstrate:
import streamlit as st
import pandas as pd
df = pd.DataFrame({"A": [1, 2, 3, 4], "B": [1, 2, 3, 4]})
styled_df = df.style.format({"B": "{:.2f}€"})
if 'df' not in st.session_state:
st.session_state.df = df
st.session_state.styled_df = styled_df
col1, col2 = st.columns(2)
with col1:
st.subheader("Styled df in session state")
st.data_editor(
st.session_state.styled_df,
key="display",
disabled=("B"),
)
with col2:
st.subheader("Styled df redefined each rerun")
st.data_editor(
styled_df,
key="display2",
disabled=("B"),
)
st.write('Styler equivalency: ' + str(st.session_state.styled_df == styled_df))
st.write("Streamlit version: ", st.__version__)
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.