URL: https://linuxfr.org/news/graphdash-ou-comment-construire-une-interface-web-simple-pour-vos-graphes Title: GraphDash, ou comment construire une interface web simple pour vos graphes Authors: Alex Benoît Sibaud et claudex Date: 2016年06月29日T09:28:31+02:00 License: CC By-SA Tags: python, web, visualisation, python3 et flask Score: 29 `GraphDash` est un outil développé en Python (avec Flask) et publié sous licence Apache v2. Il permet de construire une interface web à partir de graphes dont vous disposez. Il vous suffit simplement d'ajouter un fichier contenant des métadonnées. Par exemple: ```bash $ ls default_graph_dir graph.svg graph.txt ``` `graph.svg` est votre graphe, et `graph.txt` contient quelques métadonnées au format YAML: ```bash $ cat default_graph_dir/graph.txt name: graph.svg family: Category 1 title: '*Real serious* graph' ``` Vous pouvez bien évidemment placer autant de graphes que vous le souhaitez dans le répertoire, et ensuite lancez `GraphDash`. Vous obtiendrez une interface web permettant de naviguer, chercher et d'afficher vos graphes. ```bash $ GraphDash -r default_graph_dir * Running on http://0.0.0.0:5555/ (Press CTRL+C to quit) ``` ---- [GitHub](https://github.com/AmadeusITGroup/GraphDash) [Site](https://amadeusitgroup.github.io/GraphDash/) ----  Installation ------------ L'installation peut se faire depuis le package Python (ici en espace utilisateur): ```bash pip install --user graphdash ``` Démarrer GraphDash ------------------ Pour l'installation en espace utilisateur, vérifiez que votre `$PATH` inclut `~/.local/bin`. ```bash $ GraphDash -r default_graph_dir * Running on http://0.0.0.0:5555/ (Press CTRL+C to quit) ``` L'interface peut être configurée avec un fichier au format YAML (lui aussi), et l'option `-c/--conf`: ```bash $ cat docs/example.conf root: ../default_graph_dir title: "Example of title ;)" subtitle: "Example of subtitle" $ GraphDash -c docs/example.conf * Running on http://0.0.0.0:5555/ (Press CTRL+C to quit) ``` Un exemple de fichier de configuration peut être généré comme cela: ```bash $ GraphDash -C template.conf ``` En production avec Gunicorn --------------------------- Si vous souhaitez pouvoir facilement démarrer, arrêter et relancer plusieurs instances de `GraphDash`, alors il est plus simple et plus performant d'utiliser `Gunicorn`: ```bash pip install --user gunicorn ``` L'application `GraphDash` peut être importée via `graphdash:app`, donc vous pouvez utiliser: ```bash gunicorn -b 0.0.0.0:8888 --pid server.pid graphdash:app ``` Le fichier de configuration de `GraphDash` peut être défini via la variable d'environnement `CONF`. Avec `Gunicorn`, vous pouvez définir une variable d'environnement dans les instances avec `--env`: ```bash gunicorn -b 0.0.0.0:8888 --pid server.pid --env CONF=docs/example.conf graphdash:app ``` Ces commandes sont encapsulées dans un script appelé `GraphDashManage` qui permet de démarrer, arrêter et relancer plusieurs instances de `GraphDash`. `GraphDashManage` a besoin d'un fichier de configuration définissant les différentes instances et leur fichier de configuration: ```bash $ cat settings.sh ALL_MODES=( ['prod']="docs/example.conf" ['test']="docs/example.conf" ) ALL_PORTS=( ['prod']=1234 ['test']=5678 ) WORKERS=3 ``` Et voilà, vous pouvez gérer vos instances de cette manière: ```bash $ GraphDashManage start prod [INFO] Listening at: http://0.0.0.0:1234 [INFO] Booting worker with pid: 30403 [INFO] Booting worker with pid: 30404 [INFO] Booting worker with pid: 30405 $ GraphDashManage start test [INFO] Listening at: http://0.0.0.0:5678 ... ``` **NdM:** les exemples donnés ici sont illustratifs, évitez si possible de le mettre en écoute sur 0.0.0.0 en prod pour limiter les accès non prévus.