How to use session_state to update dataframe? using streamlit and python

Viewed 35

i have streamlit app connected with database where user can update values in the dataframe.

The problem is that once the user update values the values are updated in the database but the displayed dataframe shows the old values and not the updated one.

I tried to use session_state but it did not work as it should.

so where is my error in the code below.

code:

import streamlit as st. import pandas as pd

def main():
    df = read_sql_query("""
    select * from testdb
     """,con)
    text = "out session"
    if "click" not in session_sate:
          st.session_state.click =False
          st.write(df)
    else:
          if st.session_state.click = False:
                 text = "IN session"
                 st.session_state.click =True

              # here it suppose to display the updated data after the user update values.
                 st.write(df)
          else:
                 text = "OUT session"
                 st.session_state = False
                 st.write(df)
    st.button(text)

the Button text is changed each time the app run means on each event the button text changed.

So it seems that i am not understanding how and where to use the session_state

0 Answers
Related