I created a component that allows users to build condition trees (nested and/or conditions) that can be used, for example, to filter a dataframe or build a query.
Hello, thank you for very useful component.
I have a question:
Is it possible to set a default tree within your component? I noticed in the https://condition-tree-demo.streamlit.app/ demo that some default conditions are already set. Could you please provide a code example that demonstrates how to achieve this?
Good afternoon @w3hbi, I think what you are looking for is the condition tree.
Once you have defined a key for the component, the tree is accessible through st.session_state[key] (cf readme & demo).
I made a simple script that takes tree result from session_state[key] and make changes to create a new tree that can be displayed on a graph using st_echart i found this is a good solution for me.
I’m using it in a form and am getting an issue with the form cutting off the lower half of the top level buttons upon first load. This issue goes away after interacting with the page.
I’ve posted the issue here. The result looks like this:
But sadly only that filter option will be available on the menu.
I am looking to have a default filter being used since the filter window won´t be displayed until you add a filter element which might confuse people when they see a blank window.
The othe issue i am having when used in combination with st.popover or experimental dialog the filter will reset after closing the popover or experimental dialog. Has anyone a work around?
Thanks a lot for your component, it is absolutely amazing!
It says in the doc that the RHS can be “functions (arguments also can be values/fields/funcs)” but I have trouble understanding how to do so. For instance, I would like a rule to be : Field1 >= Quantile(Field1, 10%). How is it possible to do so? My workaround so far is to prepare the initial dataframe with additional quantile columns that are treated as “regular” fields but I believe it might exist a more elegant solution.
I have another question regarding the filtering process: is it possible to see the impact of each rule one-by-one?
I agree that it can be quite confusing for the user when the tree is empty since the component does not appear. To resolve this, I invite you to check the parameters placeholder and always_show_buttons (see doc). You can also define an initial filter tree with the parameter tree.
Regarding the combination with st.popover and dialogs, I noticed the issue as well. However, I have no idea on how to maintain the component value when its container is closed. If anyone has suggestions on how to address this, I am open to ideas.
However, defining funtions is currently not possible since it requires javascript code injection into the config. I’ll implement this feature when I have time but not sure if I will make it soon. I also just corrected the doc to remove the “func” as possible source for RHS.
Regarding your second question, I’m not entirely sure what you mean, but I guess you might be able to manipulate the query string before filtering your DataFrame.
I just release version 0.2.0, that supports javascript code injection into the config. Therefore, you can now integrate validators and functions in the query builder.
I’ve taken a lot of inspiration from the streamlit-echarts and streamlit-aggrid code for this, so thanks to their creators !
I also added a new page in the demo to show how to build a complex config and inject javascript code.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.