Schluca / streamlit_tree_select

A simple and elegant checkbox tree for Streamlit.
MIT License
80 stars 9 forks source link

Keeping the expanded state of the tree! #7

Closed nimeshrevo closed 1 year ago

nimeshrevo commented 1 year ago

Hello,

I want to keep the current state, of expansion of the tree even when some action is done. I tried with the following code, but it turns out that expansion needs to be done twice.

if "current_expanded_folder" not in st.session_state:
    st.session_state.current_expanded_folder = []

checked_value = tree_select(
                    nodes,
                    expanded= st.session_state.current_expanded_folder,
                )
st.session_state.current_expanded_folder = checked_value["expanded"]

streamlit tree

Any clues would be appreciated! Thank you!

nimeshrevo commented 1 year ago

Got it's solution for now, a simple hack worked as the state was not being updated, just posting in any case if someone requires it. The idea is to wrap the last statement with while loop.

while state.expanded_nodes != tree_value["expanded"]:
         state.expanded_nodes = tree_value["expanded"]