Skip to main content

Streamlit Component for ANT Tree

Project description

Streamlit ANT Tree Select Component

The Streamlit ANT Tree Select Component adds a hierarchical dropdown selector to Streamlit, based on Ant Design Tree Select. It supports nested selections, multiple selection, and search functionality.

Live Demo

Installation

Install with pip:

pip install st-ant-tree

Usage

The component is initialized by calling st_ant_tree. It returns a list of selected values.

from st_ant_tree import st_ant_tree

# Define tree data
tree_data = [
    {
        "value": "parent_1",
        "title": "Parent 1",
        "children": [
            {"value": "child_1", "title": "Child 1"},
            {"value": "child_2", "title": "Child 2"},
        ],
    },
    {"value": "parent_2", "title": "Parent 2"},
]

# Use the component
selected_values = st_ant_tree(
    treeData=tree_data,
    treeCheckable=True,
    allowClear=True
)

st.write(f"Selected values: {selected_values}")

Tree Data Structure

The tree data should be a list of dictionaries, where each dictionary represents a tree node. Keys include:

  • value (required): The value returned when the node is selected.
  • title (required): The label shown in the dropdown (can include HTML).
  • children (optional): A list of child nodes (nested structure).
  • disabled (optional): Disables the node.

Default Selection

To set a default selection, use the defaultValue parameter with a list of node values.

# Define tree data
tree_data = [
    {
        "value": "parent_1",
        "title": "Parent 1",
        "children": [
            {"value": "child_1", "title": "Child 1"},
            {"value": "child_2", "title": "Child 2"},
        ],
    },
    {"value": "parent_2", "title": "Parent 2"},
]

# Set default selection
selected_values = st_ant_tree(
    treeData=tree_data,
    defaultValue=["child_1"],  # List of default selected values
    treeCheckable=True
)

Parameters

Key parameters and their purpose:

  • treeData (list): The hierarchical data for the dropdown.
  • defaultValue (list): Preselected values.
  • allowClear (bool): Enables clearing selected values.
  • treeCheckable (bool): Adds checkboxes for multi-select.
  • showSearch (bool): Enables search functionality.
  • max_height (int): Maximum height of the dropdown.
  • width_dropdown (str): Width of the dropdown (e.g., "90%").
  • placeholder (str): Placeholder text for the selector.
  • treeLine (bool): Displays lines connecting tree nodes.

Example: Searchable Dropdown

# Define tree data
tree_data = [
    {
        "value": "parent_1",
        "title": "Parent 1",
        "children": [
            {"value": "child_1", "title": "Child 1"},
            {"value": "child_2", "title": "Child 2"},
        ],
    },
    {"value": "parent_2", "title": "Parent 2"},
]

# Create a searchable dropdown
selected_values = st_ant_tree(
    treeData=tree_data,
    showSearch=True,
    placeholder="Search and select",
    treeCheckable=True
)

st.write(f"Selected values: {selected_values}")

Features

  • Nested Selections: Supports parent-child relationships in dropdowns.
  • Multiple Selection: Enable with treeCheckable=True.
  • Search: Matches input with both value and title of nodes.
  • Custom Styling: Use HTML in title or modify dropdown dimensions.

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

st_ant_tree-0.0.16.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

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

st_ant_tree-0.0.16-py3-none-any.whl (1.1 MB view details)

Uploaded Python 3

File details

Details for the file st_ant_tree-0.0.16.tar.gz.

File metadata

  • Download URL: st_ant_tree-0.0.16.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for st_ant_tree-0.0.16.tar.gz
Algorithm Hash digest
SHA256 6419201f084381b356301cc0e1c4625256562e39ea08965034f57f6a2dd09733
MD5 82f1971bc269ec2eaa4260b3459f54ef
BLAKE2b-256 bd2e80c3d960519dbe248c26fd1c76e5cfada325443c2f0d8ea35719ae7f8ba8

See more details on using hashes here.

File details

Details for the file st_ant_tree-0.0.16-py3-none-any.whl.

File metadata

  • Download URL: st_ant_tree-0.0.16-py3-none-any.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for st_ant_tree-0.0.16-py3-none-any.whl
Algorithm Hash digest
SHA256 d258b6202b838793492f0503823c99158293a107987c8df256e5dd6ec6da8104
MD5 cbbd63cfbc0e483d1cc9e3ccae6adde7
BLAKE2b-256 ff6e87d33a8b10d40b3d8100f26a63ab24828fe7b0698d348e4f504422b8b1df

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