Skip to main content

No project description provided

Project description

streamlit tree independent components

Component Image

Component is React component designed to render a hierarchical tree view with checkboxes, integrated with Streamlit for use within Streamlit applications. It allows users to navigate and select items in a nested structure, with customizable icons and state management features.

Features

Hierarchical Tree Structure:

Renders a nested tree structure using TreeView and TreeItem from Material-UI. Nodes can have multiple child nodes, creating a multi-level hierarchy. Checkbox Selection:

Each node includes a checkbox for selection.

The component manages the selection state, ensuring it reflects the user's choices. Node Icon Customization:

Nodes can display different icons based on their type (None, folder, settings, document, or a default file icon).

Icons are determined using the determineIcon function.

Disabled Nodes: Nodes can be marked as disabled using the disable property. Disabled nodes are visually distinct (grayed out) and cannot be selected. The component skips these nodes when managing state changes and rendering. Parent-Child Relationship Management:

Includes functions (getChildById and findParentById) to manage selection states across parent and child nodes.

Ensures consistent selection/deselection of parent and child nodes.

State Management: Manages the state using selected (to track selected nodes) and setSelected. State updates occur whenever a user interacts with the component.

Integration with Streamlit:

Uses StreamlitComponentBase and the Streamlit API for seamless integration with Streamlit apps. Sends updated state back to the Streamlit environment for dynamic interactions. Recursive Rendering:

The renderTree method handles recursive rendering of the tree structure, ensuring all child nodes are displayed correctly.

Expandable Nodes: Includes icons for expanding (ExpandMoreIcon) and collapsing (ChevronRightIcon) nodes, enhancing navigation through the tree.

Installation instructions

pip pip install -i streamlit-tree-independent-components

Usage instructions

import streamlit as st
from streamlit_tree_independent_components import tree_independent_components


st.subheader("Component with input args")

# icon can be set as ["folder","settings","document","file", ""]
treeItems = {
   "id":"0",
   "name":"Project Dashboard",
   "icon":"",
   "disable":False,
   "children":[
      {
         "id":"1",
         "name":"Technology Expense Summary",
         "icon":"",
         "disable":False,
         "children":[
            {
               "id":"2",
               "name":"Cost Efficiency Analysis",
               "icon":"",
               "disable":False,
               "children":[
                  {
                     "id":"3",
                     "name":"Financial Data Preparation",
                     "icon":"",
                     "disable":False
                  },
                  {
                     "id":"4",
                     "name":"Database Operations Review",
                     "icon":"",
                     "disable":False,
                     "children":[
                        {
                           "id":"5",
                           "name":"Data Entry for Operations",
                           "icon":"",
                           "disable":False,
                           "children":[
                              {
                                 "id":"6",
                                 "name":"User Data Extension",
                                 "icon":"",
                                 "disable":False,
                                 "children":[
                                    {
                                       "id":"7",
                                       "name":"Data Enhancement Process",
                                       "icon":"",
                                       "disable":False,
                                       "children":[
                                          {
                                             "id":"8",
                                             "name":"Business Analysis Report",
                                             "icon":"",
                                             "disable":False
                                          },
                                          {
                                             "id":"9",
                                             "name":"Performance Overview",
                                             "icon":"",
                                             "disable":False,
                                             "children":[
                                                {
                                                   "id":"10",
                                                   "name":"Manual Input for Performance",
                                                   "icon":"",
                                                   "disable":False
                                                },
                                                {
                                                   "id":"11",
                                                   "name":"Post-Report Evaluation Post-Report Evaluation Post-Report Evaluation Post-Report Evaluation",
                                                   "icon":"",
                                                   "disable": False
                                                }
                                             ]
                                          }
                                       ]
                                    }
                                 ]
                              }
                           ]
                        }
                     ]
                  }
               ]
            }
         ]
      }
   ]
}

checkItems = ["0","1","2","3","4","5","6","7","9","8"]
if "change" not in st.session_state:
    st.session_state["change"] = checkItems
if "i" not in st.session_state:
    st.session_state["i"] = 0
if "disable" not in st.session_state:
    st.session_state["disable"] = False
if "single_select" not in st.session_state:
    st.session_state["single_select"] = False

change = st.button("Select index from 0 to 9")
if change:
    st.session_state["change"] = ["0", "1", "2", "3", "4", "5", "6", "7", "9", "8"]

change2 = st.button("Deselect all")
if change2:
    st.session_state["change"] = []

disable_toggle = st.button("Toggle Treeview View Enable/Disable")
if disable_toggle:
    st.session_state["disable"] = not st.session_state["disable"]

st.warning(f"Treeview disable! Current set: {st.session_state['disable']}")

single_select = st.button("Toggle Single Select True/False")
if single_select:
    st.session_state["single_select"] = not st.session_state["single_select"]

st.warning(f"Treeview single_select ! Current set: {st.session_state['single_select']}")

result = tree_independent_components(treeItems, checkItems=st.session_state["change"],disable=st.session_state['disable'], single_select=st.session_state["single_select"], x_scroll=True, y_scroll=True, x_scroll_width=40, frameHeight=40, border=False)
try:
   st.write(sorted(result["setSelected"], key=int))
   #st.session_state["change"] = sorted(result["setSelected"], key=int)
except:
  pass

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_tree_independent_components-0.2.4.tar.gz (709.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file streamlit_tree_independent_components-0.2.4.tar.gz.

File metadata

File hashes

Hashes for streamlit_tree_independent_components-0.2.4.tar.gz
Algorithm Hash digest
SHA256 1cc0ef9133b9d2be337402717d2ee1bf9f832db36e7ea62af2db198e711e1711
MD5 64ac4d05aaefddfbb234d3a34489a2ca
BLAKE2b-256 82c98dcc4d3964073bde387295a8d2886a169ff588ce157893b3e5b4667d33de

See more details on using hashes here.

File details

Details for the file streamlit_tree_independent_components-0.2.4-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_tree_independent_components-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 205ac7eb8775e011eefb4c29b626b33e05fb958b1bd2a50e99bc3560cb5ce261
MD5 7a71d40ef45a93bf054352847ce4af63
BLAKE2b-256 b680aa9128e2d27809e38f2d134c224c693003313b7c67da17dd4c5b5dc6fc74

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page