Aggrid table disappears after clicking the column header

Question:

When I press the button it shows the AgGrid table. However, when clicking the table it disappears. How do I make it persistent?

uploaded_file = st.file_uploader('Upload your text/csv file here')

def check_upload():
    if uploaded_file:
        df = pd.read_csv(uploaded_file)
    else:
        st.warning("Upload file first!")
    return df

# Update the csv file through button click
def terrabalance():
    st.header('Contents')

    # Read the csv file
    df = check_upload()

    # Obtain the current balance for Terra Luna
    terra = LCDClient(url="https://lcd.terra.dev", chain_id="columbus-5")
    Wallet_Address=(df.loc[:,'Address'])
    Balance_storage = []

    for address in Wallet_Address:
        balance_array = terra.bank.balance(address)
        balance = balance_array[1]['total']
        Balance_storage.append(balance)

How to call out df2 outside the function?

    df2 = pd.DataFrame(df)
    df2[today] = Balance_storage 
    gd = GridOptionsBuilder.from_dataframe(df2)
    gd.configure_default_column(editable=True, groupable=True)
    gridoptions = gd.build()
    AgGrid(df2, gridOptions=gridoptions) 

if st.button('Update Balance'): 
   terrabalance()
Asked By: noobcodersan

||

Answers:

It disappears because your button has no session state. Initialize a session state for the button.

update = st.button('Update Balance')

if "update_state" not in st.session_state:
    st.session_state.update_state = False

if update or st.session_state.update_state:
   st.session_state.update_state = True
   terrabalance() # Your function
Answered By: Jamiu Shaibu
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.