Package: dash-cytoscape-elements
dash-cytoscape-elementsThis is a Python object forDash CytoscapeElements.FeaturesAdd/Remove/Get/Filter Element(Node/Edge) on Python object.Convert Python object from/to Dash Cytoscape formatConvert Python object from/to json(Cytoscape.js format)Installpip install dash-cytoscape-elementsUsageExample1Create Elements object & using on Dash Cytoscapeimportdashimportdash_cytoscapeascytofromdashimporthtmlfromdash_cytoscape_elementsimportElementse=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)Example2Edit json file of Elements.fromdash_cytoscape_elementsimportElementse=Elements.from_file("elements.json")e.remove(id="node2")e.remove(source="node1",target="node2")withopen("elements.json",mode='w')asf:f.write(e.to_json())Supported ParametersThis package supports the following parameters ofDash CytoscapeElement.ParameterTypeElementidstrNode, EdgeparentstrNodesourcestrEdgetargetstrEdgelabelstrNode, Edgesource_labelstrEdgetarget_labelstrEdgexfloatNodeyfloatNodeclassesstrNode, EdgeselectedstrNode, EdgeselectablestrNode, EdgelockedstrNode, EdgegrabbablestrNode, EdgepannablestrNode, EdgescratchdictNode, Edgeexample 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:fromtypingimportList,Setfromdash_cytoscape_elementsimportGenericElementsfromdash_cytoscape_elements.elementimportEdge,EdgeData,Node,NodeDataclassCustomNodeData(NodeData):custom_str1:str=""classCustomNode(Node):data:CustomNodeData=CustomNodeData()custom_str2:str=""custom_list:List[str]=[]classCustomEdgeData(EdgeData):custom_str1:str=""classCustomEdge(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 theDocumentationfor details.