Skip to main content

Streamlit Component Wrapper for React Flow, modified for Flowco. Original: https://github.com/dkapur17/streamlit-flow

Project description

Streamlit Flow Logo

Streamlit Flow

Streamlit App

Build beautiful, interactive flow diagrams: Powered by React Flow, Simplified by Streamlit.

Markdown Support in Node

🎉 Version 1.6.1 is out now! 🎉

[!WARNING]

StreamlitFlow v1.6.1 has breaking changes. Please read on to understand how to migrate your code to the new version.

This version of StreamlitFlow fixes 2 major issues:

  1. Memory leak when interacting with the component (thanks @yyahav for bringing this up).
  2. Component not reflecting state changes made in Python.

A side-effect of synchronizing the frontend and backend changes is that if the state is defined in a way that its re-initialized with every re-run, it would cause the component to re-render infinitely and will hang your streamlit app. You must store the state as part of the session_state to prevent it from re-initalizing every run.

DON'T

state = StreamlitFlowState(nodes, edges)
streamlit_flow('key', state)

DO

if 'state' not in st.session_state:
    st.session_state.state = StreamlitFlowState(nodes, edge)
streamlit_flow('key', st.session_state.state)

Features

  • Create, edit and visualize beautiful flow diagrams.
  • Add nodes and edges, move them around, pan and zoom.
  • Edit node and edge properties.
  • Easy to use Layouts - Layered, Tree, Force, Stress, Radial, Random, and Manual.
  • Markdown Support in Nodes.
  • Interactions with Streamlit - clicks on nodes and edges can be captured in Streamlit.
  • Synchronized state management - changes to the state of the flow can be made seamlessly from the UI through user interactions as well as programmatically in Python, and the changes reflect on the UI without any state modification wizardry.

A demo for all these features can be found here.

Installation

pip install streamlit-flow-component

Running the example

Install the dependencies

git clone https://github.com/dkapur17/streamlit-flow.git
cd streamlit-flow
npm install --prefix streamlit_flow/frontend

Run the frontent

On the first terminal, run from the root of the repository

cd streamlit_flow/frontend
npm start

Run this Example Streamlit App

On the second terminal, run from the root of the repository

streamlit run example.py

Change log

Version 1.5.0

[!WARNING]

StreamlitFlow v1.5.0 has breaking changes. Please read on to understand how to migrate your code to the new version.

Say hello to the new and improved state management system that syncs the states between changes in the frontend and the backend. This means that you can now modify the state of the flow diagram from Python and see the changes reflected in the frontend without having to hack into the component's state.

Note: The updated state management uses a new StreamlitFlowState class to manage the state within streamlit. Instead of taking nodes and edges as arguments, the streamlit_flow function now takes a single StreamlitFlowState object. This means that code using earlier versions of this library will need to be tweaked slightly to work with the new version.

Old

from streamlit_flow import streamlit_flow
from streamlit_flow.elements import StreamlitFlowNode, StreamlitFlowEdge

nodes = [...]
edges = [...]

streamlit_flow('flow', nodes, edges)

New

from streamlit_flow import streamlit_flow
from streamlit_flow.elements import StreamlitFlowNode, StreamlitFlowEdge
from streamlit_flow.state import StreamlitFlowState

nodes = [...]
edges = [...]
state = StreamlitFlowState(nodes, edges)

streamlit_flow('flow', state)

The benefits we get from this are significant, as the StreamlitFlowState class makes sure that the states in the frontend and the backend are synced wth the latest changes from either side.

Example

from streamlit_flow import streamlit_flow
from streamlit_flow.elements import StreamlitFlowNode, StreamlitFlowEdge
from streamlit_flow.state import StreamlitFlowState
from uuid import uuid4

# Initialize the state if it doesn't exist
if 'flow_state' not in st.session_state:
    nodes = [...]
    edges = [...]
    st.session_state.flow_state = StreamlitFlowState(key="flow", nodes, edges)

# Use any operation that alters the state, for example add node, and then rerun
if st.button("Add node"):
    new_node = StreamlitFlowNode(id=str(f"st-flow-node_{uuid4()}"), 
                                pos=(0, 0), 
                                data={'content': f'Node {len(st.session_state.flow_state.nodes) + 1}'}, 
                                node_type='default', 
                                source_position='right', 
                                target_position='left')
    st.session_state.flow_state.nodes.append(new_node)
    st.rerun()

# Use the state as the argument, as well as to store the return value
st.session_state.flow_state = streamlit_flow('flow', st.session_state.flow_state)

Minor Updates

  • More Robust Returns: The streamlit_flow component now returns the updated state on several user interactions, such as creating/deleting/editing/moving a node or an edge, to make sure the states stay synced.
  • Edge Markers: Ends of the edges can now be set to arrow or arrowclosed to represent directed edges, as well as further styled. Check out the style options here.
  • Unified node dimensions: Streamlit flow now only sets the dimensions of the nodes in the style dictionary, and let Reactflow handle computing the dimensions. This means that the width and height attributes of the nodes are now deprecated.

Version 1.2.9

  • Markdown Nodes: Use Markdown and HTML in the nodes to make them more expressive.

Version 1.0.0

  • Overhauled State Management: The component now manages the state of the flow diagram automatically. As such, it keeps track of changes to node positions, connections, and more.

  • Pane Context Menu: Right-clicking on the canvas now opens a context menu, allowing you to add new nodes or reset the layout.

  • Node Context Menu: Right-clicking on a node now opens a context menu, allowing you to edit or delete the node.

  • Edge Context Menu: Right-clicking on an edge now opens a context menu, allowing you to edit or delete the edge.

  • Way more Layouts: The layouts are now more extensive, including Tree, Layered, Force, Stress, Radial, Random and Manual. One can also make a custom layout by inheriting from the Layout class.

  • Hackable Python State: The primary state management is done within the component, and the state can be read by Python. This is the intended usage. However, while not recommended, it is possible to modify the state from Python as well if the user wishes to.

Version 0.6.0

  • The initial release of the library, with the ability to visualize flow diagrams.
  • Create nodes and edges, move them around, pan and zoom.
  • Automatic Layered Layout Supported
  • Interactions sent to Streamlit - The component returns the ID of the element that was clicked on.

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

flowco_streamlit_flow-0.0.1.tar.gz (2.1 MB view details)

Uploaded Source

Built Distribution

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

flowco_streamlit_flow-0.0.1-py3-none-any.whl (2.1 MB view details)

Uploaded Python 3

File details

Details for the file flowco_streamlit_flow-0.0.1.tar.gz.

File metadata

  • Download URL: flowco_streamlit_flow-0.0.1.tar.gz
  • Upload date:
  • Size: 2.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for flowco_streamlit_flow-0.0.1.tar.gz
Algorithm Hash digest
SHA256 491bf238c6515064e76d5513ec6e9383675e69ff8687c991d94b0c030a8e4a81
MD5 310852e220ef8291d4aaf3ffcc3b679f
BLAKE2b-256 47b898db2a35031a0c52571f0e479348611cc9a353fabb2f74b7d307d09d35b6

See more details on using hashes here.

File details

Details for the file flowco_streamlit_flow-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for flowco_streamlit_flow-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fcc58b1abbec3136f109863f035498b9e89da0c2d15666f9b5ea40d9a67482cb
MD5 e303a054ca6969f05a81ac9448a1ca54
BLAKE2b-256 af4d6b229bbca85bea1e62ed906ab1644ecea29af2026a52d77824715a46219f

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