Skip to main content

dash-cytoscape-elements

test PyPI - Python Version PyPI GitHub

This is a Python object for Dash Cytoscape Elements.

Features

  • Add/Remove/Get/Filter Element(Node/Edge) on Python object.
  • Convert Python object from/to Dash Cytoscape format
  • Convert Python object from/to json(Cytoscape.js format)

Install

pip install dash-cytoscape-elements

Usage

Example1

Create Elements object & using on Dash Cytoscape

import dash
import dash_cytoscape as cyto
from dash import html
from dash_cytoscape_elements import Elements

e = Elements()
e.add(id="one", label="Node 1", x=50, y=50)
e.add(id="two", label="Node 2", x=200, y=200)
e.add(source="one", target="two", label="Node 1 to 2")

app = dash.Dash(__name__)
app.layout = html.Div([
    cyto.Cytoscape(
        id='cytoscape',
        elements=e.to_dash(),
        layout={'name': 'preset'}
    )
])

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

Example2

Edit json file of Elements.

from dash_cytoscape_elements import Elements

e = Elements.from_file("elements.json")
e.remove(id="node2")
e.remove(source="node1", target="node2")

with open("elements.json", mode='w') as f:
    f.write(e.to_json())

Supported Parameters

This package supports the following parameters of Dash Cytoscape Element.

Parameter Type Element
id str Node, Edge
parent str Node
source str Edge
target str Edge
label str Node, Edge
source_label str Edge
target_label str Edge
x float Node
y float Node
classes str Node, Edge
selected str Node, Edge
selectable str Node, Edge
locked str Node, Edge
grabbable str Node, Edge
pannable str Node, Edge
scratch dict Node, Edge

example output:

>>> e = Elements()
>>> e.add(id="node1", parent="parent1", label="node_label1", x=1, y=1, classes="class1")
>>> e.add(source="node1", target="node2", label="edge_label1", source_label="source_label1", target_label="target_label1", classes="class1")
>>> print(e.to_json())
[
    {
        "group": "nodes",
        "classes": "class1",
        "data": {
            "id": "node1",
            "parent": "parent1",
            "label": "node_label1"
        },
        "position": {
            "x": 1.0,
            "y": 1.0
        }
    },
    {
        "group": "edges",
        "classes": "class1",
        "data": {
            "id": "49082bcd-dcbb-4db7-b369-29e3bf8f74e2",
            "source": "node1",
            "target": "node2",
            "label": "edge_label1",
            "source-label": "source_label1",
            "target-label": "target_label1"
        }
    }
]

How to add your own parameters:

from typing import List, Set
from dash_cytoscape_elements import GenericElements
from dash_cytoscape_elements.element import Edge, EdgeData, Node, NodeData


class CustomNodeData(NodeData):
    custom_str1: str = ""

class CustomNode(Node):
    data: CustomNodeData = CustomNodeData()
    custom_str2: str = ""
    custom_list: List[str] = []

class CustomEdgeData(EdgeData):
    custom_str1: str = ""

class CustomEdge(Edge):
    data: CustomEdgeData = CustomEdgeData()
    custom_str2: str = ""
    custom_set: Set[str] = set()

e = GenericElements[CustomNode, CustomEdge]()
e.add(id="node1", custom_str1="str1", custom_str2="str2", custom_list=["list1", "list2"])
e.add(id="edge1", source="node1", target="node2", custom_str1="str1", custom_str2="str2", custom_set={"set1", "set2"})

print(e.to_json())
# [
#     {
#         "group": "nodes",
#         "data": {
#             "id": "node1",
#             "custom_str1": "str1"
#         },
#         "custom_str2": "str2",
#         "custom_list": [
#             "list1",
#             "list2"
#         ]
#     },
#     {
#         "group": "edges",
#         "data": {
#             "id": "edge1",
#             "source": "node1",
#             "target": "node2",
#             "custom_str1": "str1"
#         },
#         "custom_str2": "str2",
#         "custom_set": [
#             "set1",
#             "set2"
#         ]
#     }
# ]

Please see the Documentation for details.

Metadata

Release files for dash-cytoscape-elements 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dash-cytoscape-elements 0.0.4
File Size Uploaded
dash-cytoscape-elements-0.0.4.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dash-cytoscape-elements 0.0.4
File Interpreter ABI Platform
dash_cytoscape_elements-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 16.0 kB

Release files / dash-cytoscape-elements-0.0.4.tar.gz

Download URL dash-cytoscape-elements-0.0.4.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
706d23a9009f47c9b083d309c38cca74d77d43938db27c20de72d5de6da86048
BLAKE2b-256 checksum
How to use checksums
fa2657dd13598ca3c5e12bba0db746be393895cf84fad6177abac75a1fb05c35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.7.12 Darwin/22.3.0

Release files / dash_cytoscape_elements-0.0.4-py3-none-any.whl

Download URL dash_cytoscape_elements-0.0.4-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
738d51f36ce84ce830114f19e13c78cf1b91d532150ed1c9ea72243129003c0d
BLAKE2b-256 checksum
How to use checksums
18512a899b22454f6309f4f0f8715537dd3e9e97c03af0fe0b9de39d5be53343
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.7.12 Darwin/22.3.0

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page