I am encountering an issue with my app which I have simplified into a nice example, here:
import streamlit as st import pandas as pd def function(): # Parsing the string into a list using json.loads person_title_strings3 = ['accountant','chef','friend'] # Converting the list into a DataFrame df_job_titles = pd.DataFrame(person_title_strings3, columns=['Job Title']) # To display the DataFrame (optional) with st.form("my_form"): edited_df = st.data_editor(df_job_titles, num_rows="dynamic") submitted = st.form_submit_button("Submit") if submitted: st.write("Edited dataframe:", edited_df) if st.button('Press to see df'): function()
When I run this code:
- first the user presses this button to see a df
then, they can edit the dataframe using st.data_editor:
and upon submit, I want the dataframe to be saved and displayed (so it can be used later in the function I do some computation on their updated dataframe).
But there is an issue! as you can see if you run the example provided, when you press submit, everything disappears! the user’s edits go away and we have refreshed the page :(. The dataframe edits are not saved for me to continue with my functions.
Do you have any advice? Is this possible?
The reason I NEED to display the dataframe only after the first button click (“press to see df”, in this example) is because the dataframe is first created with user inputting a sentence in the sidebar like “I am a student looking to talk to experts to get their advice”, which when you press “press to see df” calls the openAI API, which makes the first iteration of the dataframe with relevant job titles for the user to talk to, which is displayed. I then want the user to be able to edit this dataframe & then my code will do more functions after the user input, like call the Apollo API to get email addresses for those job titles.
Is this possible? I could use some help on the dataframe not dissappearing after the user edits it & tries to save it
I am running locally with streamlit version 1.28.2 and python version 3.10.10