Coder Social home page Coder Social logo

jacquesfize / sigmajs_for_dash Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 327 KB

Component to use SigmaJS in your Dash application

License: Other

R 5.03% Python 37.28% HTML 0.60% Julia 8.38% JavaScript 48.71%
dash-plotly sigmajs data-visualization network

sigmajs_for_dash's Introduction

SigmaJS for Dash

SigmaJS for Dash is a component that bring SigmaJS network fast renderer to your Dash app.

Available features :

  • Highlight node neighbors by clicking it
  • Zoom on a node (or given coordinates) to emphasize part of your network right at the beginning
  • Node searching features
  • Works with networkx graph

Setup

Run the following command to install the component.

pip install git+https://github.com/Jacobe2169/sigmajs_for_dash

Get Started

Try it !

A demo is available in the usage.py script. Just run the command :

python usage.py

The application should render a network like the animated gif below.

Screenshot of the app in usage.py

Use the component

Let's start with a simple Dash application. We'll use the following script.

from sigmajs_for_dash import SigmaJSComponent
from sigmajs_for_dash.utils import networkx2Sigma

from dash import Dash, html
import networkx as nx
import json

app = Dash(__name__)


app.layout = html.Div([
    html.H1("Hello World")
])

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

SigmaJS only accepts network data in JSON format. Therefore, there are two options:

  1. Create a Python dictionary following the JSON format described here.
{
  "attributes": { # Graph attributes
    "name": "place holder"
  },
  "options": {
    "multi": False,
    "allowSelfLoops": True,
    "type": "directed"
  },
  "nodes": [ # Nodes declaration
    {
      "key": "53", # node id
      "attributes": {
        "label": "Changement Climatique", # node label (displayed on screen)
        "x": 639.0149, # node x position
        "y": -703.6634, # node y position
        "size": 99.99999, # node size (displayed on screen)
        "color": "#66ff66", # node color (displayed on screen)
        # Check SigmaJS's documentation for other graphical customization options 
      }
    },
    #...
    ],
   "edges":[ # Edges declaration
    {
      "key": "0", # edge id
      "source": "0", # edge source
      "target": "1", # edge target
      "attributes": {# edge attributes
        "weight": 1.0
      }
    },
    //...
   ]
  1. Use the networkx library and its networkx.Graph object. The latter requires the networkx2Sigma() function to convert the networkx graph into a SigmaJS usable dictionary.
# Using networkx 
G = nx.karate_club_graph()
data = networkx2Sigma(G)

Once your network data is ready, simply add the component in your Dash app layout :

app.layout = html.Div(
    [
        html.H1("Hello"),
        SigmaJSComponent(
            id='graph_container',label="graph_container",
            graph_data=data,style={"height":"600px","width":"600px"}
        )
    ]
)

Acknowledgments

This library is a simple wrapper around the fabulous SigmaJS(+ graphology) library proposed by the Sciences-Po Médialab and OuestWare. Check their website !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.