Hello All,
I recently developed an streamlit app using “Streamlit in Snowflake” and found that if 2 users login separately on different machine and editing the data, On submit from one user, data refreshes (Page itself) on another user screen who is currently updating and yet to submit.
Although, I’ve handled it using session state to store the whole data frame and it comes back as is on auto refresh but looking for the reason as well as best way to handle that if not session state.
Below is a basic sample code I tried to test on 2 users (parallelly). App updates a table with existing data “temp_test(code, value)”
import streamlit as st
from snowflake.snowpark.context import get_active_session
import pandas as pd
from snowflake.snowpark.functions import col
def main():
st.set_page_config(layout=“wide”)
st.title(“:green[Test]”)
session = get_active_session()
tableName = 'PUBLIC.temp_test'
dataframe = (session.table(tableName).select(col('CODE'),col('VALUE'))).to_pandas()
dataframe_init = dataframe
dataframe_init.insert(0, 'SELECT', False)
edited_df = st.data_editor(dataframe_init)
if st.button('Update'):
df_toapprove = edited_df.loc[edited_df['SELECT'] == True,['CODE','VALUE']]
query = "update "+str(tableName)+" set VALUE = '"+str(df_toapprove['VALUE'].iloc[0])+"' where CODE = '"+df_toapprove['CODE'].iloc[0]+"'"
session.sql(query).collect()
st.write(query)