Streamlit-condition-tree is a custom Streamlit component that enables users to construct complex, nested condition trees, primarily for filtering DataFrames or building database queries. The library is currently at version 0.3.0, released in October 2024, and maintains an active development status with regular updates and improvements.
pip install streamlit-condition-treeVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `streamlit-condition-tree` to filter a Pandas DataFrame dynamically. It initializes a sample DataFrame, automatically generates a configuration for the condition tree, and then uses the `condition_tree` component to construct a query string. The DataFrame is then filtered using the generated query.
To revert to the previous behavior (buttons only on hover), explicitly set `always_show_buttons=False` when calling `condition_tree()`.
Thoroughly review and sanitize any injected JavaScript code. Ensure it comes from trusted sources and does not expose sensitive information or introduce XSS vulnerabilities.
Always provide a unique `key` to `condition_tree` if you intend to programmatically control its state or access the generated tree via `st.session_state[key]`. If the component's `config` changes, ensure the `key` is stable, or use `st.session_state` to manage the initial `tree` parameter for persistence.
Assign a `key` to the `condition_tree` component. Access `st.session_state[key]` to get the current tree structure and pass this dictionary to the `tree` parameter in subsequent calls to load it.
pip install streamlit-condition-tree
Ensure each call to `condition_tree_widget()` has a unique `key` argument, e.g., `condition_tree_widget(df=df, key='unique_key_1')`.
Convert your data into a pandas DataFrame before passing it to the widget: `df = pd.DataFrame(my_list_of_dicts)`.
You need to parse the returned dictionary (e.g., by converting it to an SQL-like query string) to apply the conditions to your DataFrame.