Basic Usage¶
Installation¶
$ pip install Flask-VisJS
Initialization¶
from flask_visjs import VisJS4
from flask import Flask
app = Flask(__name__)
VisJS4().init_app(app)
Create a simple network¶
from flask_visjs import Network
my_network = Network()
# add some data
my_network.add_node(1, label='First node', shape='box')
my_network.add_node(2, title='Second node', shape='circle')
my_network.add_node('third', title='Third node', shape='ellipse')
# connect the nodes
my_network.add_edge(1, 2)
my_network.add_edge(2, 'third', value=2)
my_network.add_edge('third', 1, title='Foo')
return render_template('your_template.html.j2', graph=my_network)
Use the network in the template¶
<html>
<head>
{{ graph.inject_css() }}
</head>
<body>
{{ graph.inject_js() }}
{{ graph.inject_graph() }}
</body>
</html>
Check out the visjsdocs for all possible options.
Resources Helpers¶
graph.inject_css()
and graph.inject_js()
.
Everytime you want to visualize a network, you have to use these helper functions, which add the needed visjs code to your html site.
Run the examples¶
Flask-VisJS provides some example apps which should get you easily started. See Run the examples for the details.
Configurations¶
Configuration Variable |
Default Value |
Description |
---|---|---|
VISJS_CDN_TEMPLATE |
The url (with f-string vars) to load the libraries from when the files aren’t locally served |
|
VISJS_JS_FILENAME |
|
The filename of the javascript file which will be used by the |
VISJS_CSS_FILENAME |
|
The filename of the css file which will be used by the |
VISJS_SERVE_LOCAL |
|
If set to |
VISJS_CUSTOM_TEMPLATE_PATH |
|
The absolute path to the graph template which will be used by the |
VISJS_VERSION |
|
The visjs version to use. The default depends on the class you use |