Dash Cytoscape

1.0.2 · active · verified Thu Apr 16

Dash Cytoscape is a component library for Dash, enabling interactive network visualization in Python applications. It wraps the powerful Cytoscape.js library and offers deep integration with Dash layouts and callbacks, facilitating the creation of sophisticated graphs from data, including those from libraries like NetworkX. The current version is 1.0.2, with active development and regular updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart creates a simple Dash application displaying a two-node, one-edge graph. It demonstrates basic `Cytoscape` component usage with `elements`, `layout`, and `stylesheet` properties. Remember to run `pip install dash` first if not already installed.

from dash import Dash, html
import dash_cytoscape as cyto

app = Dash(__name__)

app.layout = html.Div([
    cyto.Cytoscape(
        id='cytoscape-two-nodes',
        layout={'name': 'preset'},
        style={'width': '100%', 'height': '400px'},
        elements=[
            {'data': {'id': 'one', 'label': 'Node 1'}, 'position': {'x': 75, 'y': 75}},
            {'data': {'id': 'two', 'label': 'Node 2'}, 'position': {'x': 200, 'y': 200}},
            {'data': {'source': 'one', 'target': 'two', 'label': 'Node 1 to 2'}}
        ],
        stylesheet=[
            {
                'selector': 'node',
                'style': {
                    'background-color': '#BFD7B5',
                    'label': 'data(label)'
                }
            },
            {
                'selector': 'edge',
                'style': {
                    'line-color': '#A3C4BC',
                    'label': 'data(label)'
                }
            }
        ]
    )
])

if __name__ == '__main__':
    app.run_server(debug=True)

view raw JSON →