Skip to content

Commit

Permalink
Merge pull request #30 from imohitmayank/prod_server
Browse files Browse the repository at this point in the history
close #29
  • Loading branch information
imohitmayank authored Aug 31, 2021
2 parents 0580226 + 8757391 commit f57324b
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 16 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,29 @@ Jaal(edge_df, node_df).plot(vis_opts={'height': '600px', # change height

For a complete list of settings, visit [vis.js website](https://visjs.github.io/vis-network/docs/network/).

### Using gunicorn

We can host Jaal on production level HTTP server using `gunicorn` by first creating the app file (`jaal_app.py`),

```python
# import
from jaal import Jaal
from jaal.datasets import load_got
# load the data
edge_df, node_df = load_got()
# create the app and server
app = Jaal(edge_df, node_df).create()
server = app.server
```

then from the command line, start the server by,

```
gunicorn jaal_app:server
```

Note, `Jaal.create()` takes `directed` and `vis_opts` as arguments. (same as `Jaal.plot()` except the `host` and `port` arguments)

## 👉 Common Problems

### Port related issue
Expand Down
2 changes: 1 addition & 1 deletion jaal/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# import Jaal at root
from .jaal import Jaal
# version in setup fetched from here
__version__ = "0.0.9"
__version__ = "0.1.0"
48 changes: 36 additions & 12 deletions jaal/jaal.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,22 +198,21 @@ def create_legends_for(title="Node", legends={}):
#
return popover_legend_children

def plot(self, debug=False, host="127.0.0.1", port="8050", directed=False, vis_opts=None):
"""Plot the network by running the Dash server
def create(self, directed=False, vis_opts=None):
"""Create the Jaal app and return it
Parameter
----------
debug (boolean)
run the debug instance of Dash?
host: string
ip address on which to run the dash server (default: 127.0.0.1)
port: string
port on which to expose the dash server (default: 8050)
directed: boolean
process the graph as directed graph?
vis_opts: dict
the visual options to be passed to the dash server (default: None)
Returns
-------
app: dash.Dash
the Jaal app
"""
# create the app
app = dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])
Expand Down Expand Up @@ -313,5 +312,30 @@ def setting_pane_callback(search_text, filter_nodes_text, filter_edges_text,
color_popover_legend_children = self.get_color_popover_legend_children(self.node_value_color_mapping, self.edge_value_color_mapping)
# finally return the modified data
return [graph_data, color_popover_legend_children]
# return server
return app

def plot(self, debug=False, host="127.0.0.1", port="8050", directed=False, vis_opts=None):
"""Plot the Jaal by first creating the app and then hosting it on default server
Parameter
----------
debug (boolean)
run the debug instance of Dash?
host: string
ip address on which to run the dash server (default: 127.0.0.1)
port: string
port on which to expose the dash server (default: 8050)
directed (boolean):
whether the graph is directed or not (default: False)
vis_opts: dict
the visual options to be passed to the dash server (default: None)
"""
# call the create_graph function
app = self.create(directed=directed, vis_opts=vis_opts)
# run the server
app.run_server(debug=debug, host=host, port=port)
app.run_server(debug=debug, host=host, port=port)
7 changes: 4 additions & 3 deletions jaal_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
'physics':{'stabilization':{'iterations': 100}}} # define the convergence iteration of network

# init Jaal and run server (with opts)
Jaal(edge_df, node_df).plot(vis_opts=vis_opts)
# Jaal(edge_df, node_df).plot(vis_opts=vis_opts)

# init Jaal and run server (with default options)
# Jaal(edge_df, node_df).plot()
# init Jaal and run server (with gunicorn)
app = Jaal(edge_df, node_df).create()
server = app.server

0 comments on commit f57324b

Please sign in to comment.