Not sure what you are looking for exactly. edited_rows is a dictionary and you acces it like any other dictionary. All the data is there as you can see in the example application.
I want to achieve the functionality that is shown here in this demo app.
The issue that I am facing now is that when I change the values in the table that I am displaying using st.data_editor, the entire page reloads for every entry that I change.
Firstly, I want to reload it only after hitting a âSaveâ button. Second, I donât want all my other components in my app to reload. Just the table should reload.
What functionality shown there are you unable to achieve?
I am not sure I understand what you mean by âreloadâ. Your script runs again each time the user interacts with a widget, as explained in the docs:
any time something must be updated on the screen, Streamlit reruns your entire Python script from top to bottom.
This can happen in two situations:
Whenever you modify your appâs source code.
Whenever a user interacts with widgets in the app. For example, when dragging a slider, entering text in an input box, or clicking a button.
You can avoid the rerun by putting some widgets in a form. But changes made to those widgets wonât be available to the application until the submit button is clicked. There is an example of that in the demo you linked.
Thanks @Goyo for the response. I have put my data editor component inside a form and now the page reloads only after clicking the form button.The âRecalculate and saveâ button in the form recalculates everything based on the edited data and saves it in the session_state variable.
However, the recalculations are visble after clicking the button twice.
I am attaching my code for reference.
Please let me know where I am going wrong or if there is any other way to achieve the same.
Also let me know which all blocks to cache and how. I have not familiar with caching in Streamlit.
import streamlit as st
session_state = st.session_state
dropdown = # code for st.selectbox()
if dropdown:
df= pd.read_csv("filename.csv")
#some extra preprocessing and function calls
df = some_preprocess(df)
grouped_df = df.groupby("Group").agg({"column_1":"sum"})
grouped_df["col2"]=1
if "original_data" not in session_state:
session_state.original_data= grouped_df
if "edited_data" not in st.session_state:
session_state.edited_data= grouped_df.copy()
def save_edits():
edited_df = session_state.edited_data
#recalculation of col2 based on edits made in the table
edited_df["col2"] = edited_df["col1"]+3
session_state.edited_data=edited_df
session_state.original_data=session_state.edited_data
with st.form("Table"):
session_state.edited_data = st.data_editor(session_state.original_data,num_rows="dynamic")
st.form_submit_button("Recalculate and save",on_click=save_edits)
The return value of the widgets in a form is only available in the next rerun, after calling the callback. In the callback, session_state.edited_data still has the old data, you cannot access the edited data from there.
I am trying to get the edited data using st.session_state.edited_rows but I get the following error:
st.session_state has no attribute âedited_rowsâ. Did you forget to initialize it? More info: Add statefulness to apps<!-- --> - Streamlit Docs
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.