Skip to main content

Streamlit component that allows you to do X

Project description

st-react-flow-pro

Streamlit component that allows you to draw a DAG / Directed Acyclic Graph with abilitty to highlight active node. It's highly customizable since it's been written in React.js with ReactFlow package.

Installation instructions

pip install st-react-flow-pro

or use

pip install --index-url https://test.pypi.org/simple/ st-react-flow-pro==0.1.0

if above command doesn't work.

Usage instructions

import streamlit as st
import time
from st_react_flow_pro import st_react_flow_pro

def main():
    st.title("ST React Flow Pro - Hierarchical Graph Traversal")

    initial_nodes = [
        {"id": "1", "data": {"label": "Start"}, "position": {"x": 100, "y": 0}},
        {"id": "2", "data": {"label": "Level 1 - A"}, "position": {"x": 300, "y": 100}},
        {"id": "3", "data": {"label": "Level 1 - B"}, "position": {"x": 100, "y": 200}},
        {"id": "4", "data": {"label": "Level 2 - A1"}, "position": {"x": 300, "y": 300}},
        {"id": "5", "data": {"label": "Level 2 - B1"}, "position": {"x": 500, "y": 200}},
        {"id": "6", "data": {"label": "Level 3 - A2"}, "position": {"x": 700, "y": 100}},
    ]

    initial_edges = [
        {"id": "e1-2", "source": "1", "target": "2"},
        {"id": "e1-3", "source": "1", "target": "3"},
        {"id": "e2-4", "source": "2", "target": "4"},
        {"id": "e3-5", "source": "3", "target": "5"},
        {"id": "e4-6", "source": "4", "target": "6"},
    ]

    if st.button("Reset Highlight Sequence"):
        st.session_state.node_index = 0
        st.rerun()

    if "node_index" not in st.session_state:
        st.session_state.node_index = 0

    if st.session_state.node_index < len(initial_nodes):
        current_node = initial_nodes[st.session_state.node_index]["id"]
        st.session_state.borderNodeId = current_node

        st.write(f"Highlighting node: {current_node}")

        st_react_flow_pro(
            initial_nodes,
            initial_edges,
            borderNodeId=st.session_state.borderNodeId,
            key="react_flow_instance"
        )

        if st.session_state.node_index < len(initial_nodes) - 1:
            time.sleep(2)
            st.session_state.node_index += 1
            st.rerun()
        else:
            st.write("Completed highlighting nodes.")
    else:
        st.write("Completed highlighting nodes.")

if __name__ == "__main__":
    main()

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_react_flow_pro-0.1.3.tar.gz (182.5 kB view details)

Uploaded Source

Built Distribution

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

st_react_flow_pro-0.1.3-py3-none-any.whl (182.1 kB view details)

Uploaded Python 3

File details

Details for the file st_react_flow_pro-0.1.3.tar.gz.

File metadata

  • Download URL: st_react_flow_pro-0.1.3.tar.gz
  • Upload date:
  • Size: 182.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for st_react_flow_pro-0.1.3.tar.gz
Algorithm Hash digest
SHA256 3f623b264dc5218dfac154385c81ab039c94c80da8430c72981084be7a5cb66a
MD5 96919166f96b3a4332cb93317e387022
BLAKE2b-256 bcb8152847a47f92e3594f8f3216ab60fbb871b0c0d433dcfe2efd0a407e8133

See more details on using hashes here.

File details

Details for the file st_react_flow_pro-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for st_react_flow_pro-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a36e83fd114cea2e26f11a87c14f333b281af8c4ad799cfaa30997935b6202bb
MD5 d13db1e41cb4bdfa0b9abc2590648e1f
BLAKE2b-256 fef7e561cb9e4b1b52edfd2fc078fe92f208678bbd62a69686e7b3e351b871f6

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