{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# JSON" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Required Strucutre of the JSON file\n", "\n", "The JSON file must have two keys: `'nodes'` and `'edges'` each of which contain a list of elements that conform to the cytoscapejs specification: https://js.cytoscape.org/#notation/elements-json" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ipycytoscape" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import json\n", "with open(\"colaData.json\") as fi:\n", " json_file = json.load(fi)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cytoscapeobj = ipycytoscape.CytoscapeWidget()\n", "cytoscapeobj.graph.add_graph_from_json(json_file)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cytoscapeobj.set_style([{\n", " 'selector': 'node',\n", " 'css': {\n", " 'background-color': 'red'\n", " }\n", " },\n", "\n", " {\n", " 'selector': 'edge',\n", " 'css': {\n", " 'line-color': 'pink'\n", " }\n", " }])" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cytoscapeobj" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.2" } }, "nbformat": 4, "nbformat_minor": 4 }