New Component: streamlit-tree-select, a simple and elegant checkbox tree

Hello everyone,

I created my first custom component for a simple and elegant checkbox tree user input.

It’s super useful if you if you would like to improve the user experience when it comes to user inputs with underlying tree like structures.

Check out the documentation on GitHub: streamlit-tree-select

12 Likes

Sexy! Will definitely use

This is such a beautiful component! Well done @Schluca, and welcome to our forum :balloon:

Beautiful! You should definitely add this to the tracker: Streamlit Components - Community Tracker so we don’t lose track of it!

Fanilo

I like this! Will think about where I might be able to use it.

1 Like

Hi @Schluca - Very useful component and I’m trying to use it with a list of 2,500+ cities arranged in a hierarchy of regions/countries/cities. I want to be able to control selection of leaf city nodes. The default behaviour is multi-select, but I have cases where I require single-select. How can I configure single selection only? Essentially, any previous selection would be removed and the current selection would be checked.

Any ideas, and/or can you add this feature please?

Also, can you please add another (optional) property to the node specification, called metadata, so one can add additional properties to the tree which will be returned in addition to the value. I could shoehorn this meta data into the value string, but it would be neater to have a metadata property.

Many thanks,
Arvindra

Thank you so much!

Hi @asehmi, thank you very much!

I’m not quite sure what you are looking for. Would you like single selection per region or countries? Should the user be able to select one city per country or one per region? Currently it is not implemented but I will have a look into it. On the react-checkbox-tree I found a discussion regarding the topic which might be possible to implement: https://github.com/jakezatecky/react-checkbox-tree/issues/206

I will definitely take a look how I could implement the metadata implementation, but if you have time and ideas feel always free to contribute.

Lucas

Thank you very much! I will definitely add it once I reached Trust Level 1. :sweat_smile:

1 Like

Hi,

If I could allow only one leaf node at a time to be selected, that would be awesome. Here’s an example tree you can use:

[
    {
        "label": "Americas",
        "value": "Americas",
        "children": [
            {
                "label": "United States",
                "value": "United States",
                "children": [
                    {
                        "label": "Boston",
                        "value": "BOS"
                    },
                    {
                        "label": "Chicago",
                        "value": "CHI"
                    },
                    {
                        "label": "New York",
                        "value": "NYC"
                    },
                    {
                        "label": "San Francisco",
                        "value": "SFO"
                    },
                    {
                        "label": "Seattle",
                        "value": "SEA"
                    },
                    {
                        "label": "United States - Total",
                        "value": "USTOT"
                    }
                ]
            }
        ]
    },
    {
        "label": "Europe",
        "value": "Europe",
        "children": [
            {
                "label": "United Kingdom",
                "value": "United Kingdom",
                "children": [
                    {
                        "label": "Cambridge",
                        "value": "CMB"
                    },
                    {
                        "label": "London",
                        "value": "LDN"
                    },
                    {
                        "label": "Oxford",
                        "value": "OXF"
                    },
                    {
                        "label": "United Kingdom - Total",
                        "value": "UKTOT"
                    }
                ]
            }
        ]
    }
]

Having a metadata property isn’t important, as I could put a json string into the value property if necessary.

What would be really useful is to auto-generate an id field on your end to make the nodes unique. Currently, (in my full tree of 2,500+ nodes) I had to fudge the label names of some nodes as they collided. E.g. the Singapore city node label needs to be made different from the Singapore country node label, because they have the same name of course. This would make it simpler to create trees with branches that have different views on the same set of nodes, e.g. viewing economic indicators by country > indicator or by indicator > country.

In summary:

  1. Configurable single node selection
  2. Use an id property to distinguish nodes (user-supplied or generated silently)

Thanks,
Arvindra

P.S. I raised a couple of issues on your GitHub repo.

1 Like