I’m using a Snowflake Streamlit native app. I aim to show a table where users can edit cell values and save changes back to the Snowflake table. However, my current code overwrites the entire table when applying a filter and updating a cell value. I want the filter to only affect data filtering, while cell updates should be the only changes reflected in the table.
Can someone help pls. Thanks
import pandas as pd
import streamlit as st
from snowflake.snowpark.context import get_active_session
import time
session = get_active_session()
st.set_page_config(layout=“wide”, page_title=“Data Editor”, page_icon=“”, initial_sidebar_state=“expanded”)
snowflake_table_name = “table”
df = session.table(snowflake_table_name)
st.sidebar.header(“Filters”)
Country = st.sidebar.selectbox(
label=“Filter Market”,
options=df.to_pandas()[“COUNTRY”].unique(), index=1
)
df_selection = df.filter(df[“COUNTRY”] == Country)
with st.form(“data_editor_form”):
st.caption(“Edit the dataframe below”)
edited = st.experimental_data_editor(df_selection, use_container_width=True, num_rows=“dynamic”)
submit_button = st.form_submit_button(“Submit”)
if submit_button:
try:
session.write_pandas(edited, “table”, overwrite=True, quote_identifiers=False)
st.success(“Table updated”)
time.sleep(5)
except:
st.warning(“Error updating table”)
st.experimental_rerun()