Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

st.data_editor is not stateful when styling disabled columns #6898

Closed
3 of 5 tasks
MathCatsAnd opened this issue Jun 24, 2023 · 1 comment · Fixed by #6915
Closed
3 of 5 tasks

st.data_editor is not stateful when styling disabled columns #6898

MathCatsAnd opened this issue Jun 24, 2023 · 1 comment · Fixed by #6915
Labels
feature:st.data_editor priority:P2 status:confirmed Bug has been confirmed by the Streamlit team type:bug Something isn't working

Comments

@MathCatsAnd
Copy link
Contributor

MathCatsAnd commented Jun 24, 2023

Checklist

  • I have searched the existing issues for similar issues.
  • I added a very descriptive title to this issue.
  • I have provided sufficient information below to help reproduce this issue.

Summary

This is a bug reported in the forum. The underlying issue is how the data editor determines equivalency of pandas stylers.

If you have a dataframe with two columns (A and B) with column B both styled and disabled, the data editor will correctly show the styled column B and editable column A. However, the widget will not be stateful unless the styler object passed to it is coming from session state. It needs to be identically the same object in memory for the data editor to be stateful. Redefining the same styler element will be viewed as "different" and cause the data editor to be recreated from scratch.

Thanks to DGR from the forum for an executable code snippet. I've modified it here to highlight the issue:

Reproducible Code Example

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(st.session_state.styled_df == styled_df)
st.write("Streamlit version: ", st.__version__)

Steps To Reproduce

  1. Change a value in column A on the left.
  2. See it updates correctly.
  3. Change a value in column A on the right.
  4. See the widget reset and not update correctly.

Expected Behavior

Two equivalently defined styler objects should be viewed as "the same" for the purposes of the widget reconnecting to an instance on the front end. The data editor should be stateful.

Current Behavior

The data editor is not stateful when passed equivalent styler objects between reruns; it requires identical pointers to the same styler object.

Is this a regression?

  • Yes, this used to work in a previous version.

Debug info

  • Streamlit version: 1.23.1
  • Python version: 3.11
  • Pandas version: 2.0.2
  • Operating System: Windows 10
  • Browser: Edge
  • Virtual environment: Conda

Additional Information

@LukasMasuch

Are you willing to submit a PR?

  • Yes, I am willing to submit a PR!
@MathCatsAnd MathCatsAnd added status:needs-triage Has not been triaged by the Streamlit team type:bug Something isn't working labels Jun 24, 2023
@LukasMasuch LukasMasuch added feature:st.data_editor status:confirmed Bug has been confirmed by the Streamlit team and removed status:needs-triage Has not been triaged by the Streamlit team labels Jun 25, 2023
@LukasMasuch
Copy link
Collaborator

@MathCatsAnd Thanks for reporting this issue. I was able to reproduce this issue and fix it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:st.data_editor priority:P2 status:confirmed Bug has been confirmed by the Streamlit team type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants