Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 20436

streamlit only updates dataframe after every second change using st.data_editor

$
0
0

I am trying to change the value in a column based on changes made by the user in a different column with st.data_editor, and want to do it live on change. But the following code only works after 2 changes and only shows the initial change.

code is run by running streamlit run main.py

main.py

from page import pagepage()

page.py

import streamlit as stimport pandas as pdboq_df = pd.DataFrame()def update_dataframe():    boq_df.loc[boq_df["ANALYZE"] == False, "TYPE"] = None    boq_df.ffill(inplace=True)def page():    global boq_df    st.write("# Test")    if st.button("Analyze", type="primary"):        boq_df = pd.DataFrame(            data={"ANALYZE": [True, False, True],"CAT": ["Car", "Truck", "Bike"],"TYPE": ["blue", False, "yellow"],"DESC": ["two door", "four door", "single"],            }        )    if not boq_df.empty:        boq_df = st.data_editor(boq_df, height=700, on_change=update_dataframe())

Viewing all articles
Browse latest Browse all 20436

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>