Skip to main content

A flexible, customizable, Streamlit component for interactive graph visualization using Cytoscape.js

Project description

streamlit-cytoscape

A flexible, customizable Streamlit component for interactive graph visualization using Cytoscape.js. This project is a fork of st-link-analysis by @AlrasheedA, who developed the bulk of the original component. This fork extends the original with additional customization options and bug fixes.

Overview

This project provides a Streamlit custom component for visualizing and interacting with graph data using Cytoscape.js. It supports customizable edge and node styles, labels, colors, captions, and icons.

Features

  • Customizable Node and Edge Styles: Easily define the appearance of nodes and edges using a variety of style options.
  • Material Icons Support: Supports a subset of Material icons for styling nodes which can be passed by name (e.g., icon='person'). Custom icons can still be used by passing a URL (e.g., icon='url(...)').
  • Customizable Layouts: Choose from different layout algorithms to arrange the graph elements.
  • Interactive Features:
    • Toolbar with fullscreen, JSON export, and layout refresh buttons.
    • View control bar for zooming, fitting, and centering the view.
    • View all properties of the selected elements in a side panel.
    • Highlights neighboring nodes or edges when an element is selected.
  • Node Actions (Expand / Remove): Enable node removal and expansion using the node_actions parameter. Removal can be triggered by a delete keydown or a remove button click, while expansion occurs on a double-click or expand button click.

Installation

pip install streamlit-cytoscape

Usage

import streamlit as st
from streamlit_cytoscape import streamlit_cytoscape, NodeStyle, EdgeStyle

st.set_page_config(layout="wide")

# Sample Data
elements = {
    "nodes": [
        {"data": {"id": 1, "label": "PERSON", "name": "Streamlit"}},
        {"data": {"id": 2, "label": "PERSON", "name": "Hello"}},
        {"data": {"id": 3, "label": "PERSON", "name": "World"}},
        {"data": {"id": 4, "label": "POST", "content": "x"}},
        {"data": {"id": 5, "label": "POST", "content": "y"}},
    ],
    "edges": [
        {"data": {"id": 6, "label": "FOLLOWS", "source": 1, "target": 2}},
        {"data": {"id": 7, "label": "FOLLOWS", "source": 2, "target": 3}},
        {"data": {"id": 8, "label": "POSTED", "source": 3, "target": 4}},
        {"data": {"id": 9, "label": "POSTED", "source": 1, "target": 5}},
        {"data": {"id": 10, "label": "QUOTES", "source": 5, "target": 4}},
    ],
}

# Style node & edge groups
node_styles = [
    NodeStyle("PERSON", "#FF7F3E", "name", "person"),
    NodeStyle("POST", "#2A629A", "content", "description"),
]

edge_styles = [
    EdgeStyle("FOLLOWS", caption='label', directed=True),
    EdgeStyle("POSTED", caption='label', directed=True),
    EdgeStyle("QUOTES", caption='label', directed=True),
]

# Render the component
st.markdown("### streamlit-cytoscape: Example")
streamlit_cytoscape(elements, "cose", node_styles, edge_styles)

API Reference

Element Description
streamlit_cytoscape Main component for creating and displaying the graph, including layout and height settings.
NodeStyle Defines styles for nodes, including labels, colors, captions, and icons.
EdgeStyle Defines styles for edges, including curve styles, labels, colors, and directionality.
Event Define an event to pass to component function and listen to.

Development

Ensure you have Python 3.10+, Node.js, and npm installed.

Setup

# Create conda environment
conda create -n streamlit_cytoscape python=3.10
conda activate streamlit_cytoscape

# Install Python package
poetry install

# Install frontend dependencies
cd src/streamlit_cytoscape/frontend
npm install

Running the App

Change _RELEASE flag in src/streamlit_cytoscape/component.py to False.

In one terminal start the frontend dev server:

cd src/streamlit_cytoscape/frontend
npm run start

In another terminal run the streamlit server:

cd examples
poetry run streamlit run app.py

Testing

poetry run black .
poetry run flake8 src/streamlit_cytoscape tests examples
poetry run mypy src/streamlit_cytoscape
poetry run pytest

Contributing

Interested in contributing? Check out the contributing guidelines. Please note that this project is released with a Code of Conduct. By contributing to this project, you agree to abide by its terms.

License

streamlit_cytoscape was created by Natalie Gill. It is licensed under the terms of the MIT license.

AI Disclosure Statement

Generative AI tools (Claude Code, Anthropic) were used as coding assistants during the development of this project. The authors maintain full responsibility for the accuracy of all code. AI-assisted outputs were reviewed and validated against expected behavior before integration.

Acknowledgments

This project is a fork of st-link-analysis by @AlrasheedA, who developed the bulk of the original component. This fork extends the original with additional customization options.

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_cytoscape-0.1.0.tar.gz (255.0 kB view details)

Uploaded Source

Built Distribution

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

streamlit_cytoscape-0.1.0-py3-none-any.whl (278.0 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_cytoscape-0.1.0.tar.gz.

File metadata

  • Download URL: streamlit_cytoscape-0.1.0.tar.gz
  • Upload date:
  • Size: 255.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for streamlit_cytoscape-0.1.0.tar.gz
Algorithm Hash digest
SHA256 393cf25ff14974d7465d4dcd59ffb5209b67f89037b720d51a31f09fe3bc41d2
MD5 14f1bb406e3af11bdc476c03e84d4623
BLAKE2b-256 3aa223e205fccf046b7a781b7ee4bba0963bf77c6888d1160757277de706a3bc

See more details on using hashes here.

Provenance

The following attestation bundles were made for streamlit_cytoscape-0.1.0.tar.gz:

Publisher: ci.yml on natalie-23-gill/streamlit-cytoscape

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file streamlit_cytoscape-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_cytoscape-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4c8ac408987b4e1f27f0f1fefc1cefd9bbafcb7aafd5fce026193815bd52179
MD5 fa68372317bbf233f4d423fca07ab10d
BLAKE2b-256 66212c841b09611600f44e9324f88ff9a5aaa48b4f75f000529d272170af4011

See more details on using hashes here.

Provenance

The following attestation bundles were made for streamlit_cytoscape-0.1.0-py3-none-any.whl:

Publisher: ci.yml on natalie-23-gill/streamlit-cytoscape

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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