On_change - st.data_editor

Summary

Hi, guys!

I am using st.data_editor so that the user can input data in the project. Point is, when I use ‘on_change’ to call a function ‘ABC’, that receives as input that same data, the function is called on the previous data, not on the ‘changed’ data.

Steps to reproduce

Code snippet:

st.session_state['demanda_sugerida_unica'] = pd.DataFrame({'demanda_sugerida_unica': [st.session_state['demanda_sugerida_unica']]})
st.session_state['demanda_sugerida_unica_edit'] = st.data_editor(st.session_state['demanda_sugerida_unica'], hide_index=True, on_change=ABC())

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior / Actual behavior

It was expected the the function ABC was run with the new st.session_state[‘demanda_sugerida_unica_edit’] value, but it’s running with the old value instead.

In other words, if my current value is X and I change it to Y, I need my function ABC to be ran with Y, not X.

Hi,
I found some helpful solutions that will help you regarding this problem you are facing.
Here is Solved discussion on streamlit:
https://discuss.streamlit.io/t/proper-use-of-on-change-with-st-experimental-data-editor/41704

Here is official documentation of streamlit:
https://docs.streamlit.io/library/api-reference/data/st.data_editor

Thank you

So, the link you sent is basically the same problem I am facing and there is no solution on that.

Let’s say I my original value is A.
When I change it, it calls a function, which uses my value to do some calculation. The problem is, when I change my value from A to B, the function is ran with A.
When I change my value from B to C, then my function uses B.

If i change my value from A to B, i need my function to use the uptaded value, which is not happening.

Is this a limitation of st.data_editor?

Thanks in advance!

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.