Update app.py
Browse files
app.py
CHANGED
|
@@ -50,7 +50,8 @@ if uploaded:
|
|
| 50 |
st.session_state.all_fields = get_all_fields(st.session_state.data)
|
| 51 |
save_to_file()
|
| 52 |
st.session_state.editor_key = str(uuid4())
|
| 53 |
-
st.
|
|
|
|
| 54 |
|
| 55 |
# --- Add New Fields fallback ---
|
| 56 |
if not st.session_state.all_fields:
|
|
@@ -70,7 +71,7 @@ if submit_add:
|
|
| 70 |
save_to_file()
|
| 71 |
st.session_state.editor_key = str(uuid4())
|
| 72 |
st.session_state.just_added = True
|
| 73 |
-
st.rerun()
|
| 74 |
|
| 75 |
# --- Wait for rerun before rendering editor ---
|
| 76 |
if st.session_state.just_added:
|
|
@@ -100,10 +101,10 @@ edited_df = st.data_editor(
|
|
| 100 |
column_config=column_configs,
|
| 101 |
)
|
| 102 |
|
| 103 |
-
# --- Save edits ---
|
| 104 |
if edited_df is not None:
|
| 105 |
new_data = edited_df.fillna("").to_dict(orient="records")
|
| 106 |
-
if new_data != st.session_state.data:
|
| 107 |
st.session_state.data = new_data
|
| 108 |
save_to_file()
|
| 109 |
st.toast("✅ Changes auto-saved!", icon="💾")
|
|
@@ -114,7 +115,7 @@ with st.expander("âž• Add New Field"):
|
|
| 114 |
if st.button("Add Field"):
|
| 115 |
if new_field and new_field not in st.session_state.all_fields:
|
| 116 |
st.session_state.all_fields.append(new_field)
|
| 117 |
-
st.rerun()
|
| 118 |
|
| 119 |
# --- Export Dataset ---
|
| 120 |
st.markdown("### 📤 Export")
|
|
@@ -135,7 +136,7 @@ with col1:
|
|
| 135 |
st.session_state.clear()
|
| 136 |
if os.path.exists(TMP_FILE):
|
| 137 |
os.remove(TMP_FILE)
|
| 138 |
-
st.rerun()
|
| 139 |
|
| 140 |
with col2:
|
| 141 |
if os.path.exists(TMP_FILE):
|
|
@@ -148,4 +149,4 @@ with col3:
|
|
| 148 |
if os.path.exists(TMP_FILE):
|
| 149 |
os.remove(TMP_FILE)
|
| 150 |
st.session_state.clear()
|
| 151 |
-
st.rerun()
|
|
|
|
| 50 |
st.session_state.all_fields = get_all_fields(st.session_state.data)
|
| 51 |
save_to_file()
|
| 52 |
st.session_state.editor_key = str(uuid4())
|
| 53 |
+
st.session_state.just_added = True
|
| 54 |
+
st.rerun() # Force rerun to update editor
|
| 55 |
|
| 56 |
# --- Add New Fields fallback ---
|
| 57 |
if not st.session_state.all_fields:
|
|
|
|
| 71 |
save_to_file()
|
| 72 |
st.session_state.editor_key = str(uuid4())
|
| 73 |
st.session_state.just_added = True
|
| 74 |
+
st.rerun() # Force rerun to update editor
|
| 75 |
|
| 76 |
# --- Wait for rerun before rendering editor ---
|
| 77 |
if st.session_state.just_added:
|
|
|
|
| 101 |
column_config=column_configs,
|
| 102 |
)
|
| 103 |
|
| 104 |
+
# --- Save edits immediately after editing ---
|
| 105 |
if edited_df is not None:
|
| 106 |
new_data = edited_df.fillna("").to_dict(orient="records")
|
| 107 |
+
if new_data != st.session_state.data: # Ensure the data has changed before saving
|
| 108 |
st.session_state.data = new_data
|
| 109 |
save_to_file()
|
| 110 |
st.toast("✅ Changes auto-saved!", icon="💾")
|
|
|
|
| 115 |
if st.button("Add Field"):
|
| 116 |
if new_field and new_field not in st.session_state.all_fields:
|
| 117 |
st.session_state.all_fields.append(new_field)
|
| 118 |
+
st.rerun() # Rerun after adding field
|
| 119 |
|
| 120 |
# --- Export Dataset ---
|
| 121 |
st.markdown("### 📤 Export")
|
|
|
|
| 136 |
st.session_state.clear()
|
| 137 |
if os.path.exists(TMP_FILE):
|
| 138 |
os.remove(TMP_FILE)
|
| 139 |
+
st.rerun() # Force rerun after export
|
| 140 |
|
| 141 |
with col2:
|
| 142 |
if os.path.exists(TMP_FILE):
|
|
|
|
| 149 |
if os.path.exists(TMP_FILE):
|
| 150 |
os.remove(TMP_FILE)
|
| 151 |
st.session_state.clear()
|
| 152 |
+
st.rerun() # Rerun after clearing session
|