Schluca / streamlit_tree_select

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

tree_select checked property doesn't select the listed nodes #2

Open asehmi opened 1 year ago

asehmi commented 1 year ago

Hi,

The tree_select checked property doesn't cause the listed nodes to be visibly selected in the tree, nor expand the branches they are in (depending on the expand_on_click setting).

Would it be possible to provide the checked nodes list in the form they would have been defined, i.e. as dict objects? It seems they need to be converted to strings, so I need to do something like checked=[json.dumps(node1), json.dumps(node2), ...] instead of simply checked=[node1, node2]. I get the pre-checked nodes back as values but as stated above the tree nodes don't visibly show as checked.

Thanks, Arvindra

alexmaite25 commented 1 year ago

+1 to this issue, which actually encompasses 2 sub-issues:

import streamlit as st
from streamlit_tree_select import tree_select

nodes = [
    {
        "value": 1,
        "label": "A",
        "children": [
            {"value": 11, "label": "AA", "children": [{"value": 111, "label": "AAA"}]},
            {"value": 12, "label": "AB"},
        ]
    },
    {
        "value": 2,
        "label": "B",
        "children": [
            {"value": 21, "label": "BA"},
            {"value": 22, "label": "BB"},
        ]
    }
]

with st.expander("Expend tree_select"):
    return_select = tree_select(
        nodes, key="key", checked=[str(n["value"]) for n in nodes]
    )

st.write(return_select)
JROBOTO commented 10 months ago

Also adding my support for this issue. If I have the value set as some string, then pass that string to the checked property, once I have created the tree, requesting the checked property back out returns the nodes I would expect to be checked yet as previously stated, they do not appear as checked on the view