Update app.py
Browse files
app.py
CHANGED
@@ -74,6 +74,11 @@ column_configs = {
|
|
74 |
}
|
75 |
|
76 |
# --- Use st.data_editor for editable table ---
|
|
|
|
|
|
|
|
|
|
|
77 |
edited_df = st.data_editor(
|
78 |
df,
|
79 |
use_container_width=True,
|
@@ -81,16 +86,20 @@ edited_df = st.data_editor(
|
|
81 |
column_config=column_configs,
|
82 |
)
|
83 |
|
84 |
-
#
|
85 |
if edited_df is not None:
|
86 |
-
|
87 |
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
-
st.toast("β
Changes auto-saved!", icon="πΎ")
|
94 |
|
95 |
# --- Add New Entry ---
|
96 |
st.markdown("### β Add New Entry")
|
|
|
74 |
}
|
75 |
|
76 |
# --- Use st.data_editor for editable table ---
|
77 |
+
# Track previous data
|
78 |
+
if "prev_data" not in st.session_state:
|
79 |
+
st.session_state.prev_data = []
|
80 |
+
|
81 |
+
# Show editable table
|
82 |
edited_df = st.data_editor(
|
83 |
df,
|
84 |
use_container_width=True,
|
|
|
86 |
column_config=column_configs,
|
87 |
)
|
88 |
|
89 |
+
# Save only if data has changed
|
90 |
if edited_df is not None:
|
91 |
+
new_data = edited_df.fillna("").to_dict(orient="records")
|
92 |
|
93 |
+
if new_data != st.session_state.prev_data:
|
94 |
+
st.session_state.data = new_data
|
95 |
+
st.session_state.prev_data = new_data
|
96 |
+
|
97 |
+
with open(TMP_FILE, "w", encoding="utf-8") as f:
|
98 |
+
for item in new_data:
|
99 |
+
f.write(json.dumps(item, ensure_ascii=False) + "\n")
|
100 |
+
|
101 |
+
st.toast("β
Auto-saved changes!", icon="πΎ")
|
102 |
|
|
|
103 |
|
104 |
# --- Add New Entry ---
|
105 |
st.markdown("### β Add New Entry")
|