-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.py
102 lines (82 loc) · 3.03 KB
/
index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python
# Just a log print
from time import time
from datetime import timedelta
# import datetime
start_time = time() # datetime.datetime.now()
print("Starting COVIDrugNet")
# adjust cwd if not launched with "python index.py"
import os
path = os.path.split(__file__)[0] # __file__.split("index.py")[0]
if path != "":
os.chdir(path)
# import modules
import dash_html_components as html
import dash_core_components as dcc
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output
from app import app
from pages import (
home,
help,
about,
contacts,
drug_target,
drug_projection,
target_projection,
error404,
) # , target_disease, target_interactors
from building_blocks import headbar, loading_banner
from callbacks import collapse_headbar_callback
server = app.server
app.layout = html.Div(
[dcc.Location(id="url", refresh=False), headbar(), html.Div(id="loading_message"),]
)
## ---------- CALLBACKS ------------
collapse_headbar_callback()
@app.callback(Output("loading_message", "children"), [Input("url", "pathname")])
def temp_loading(pathname):
if pathname:
return loading_banner
@app.callback(Output("page_content", "children"), [Input("url", "pathname")])
def display_page(pathname):
if pathname in ["/covidrugnet", "/covidrugnet/", "/covidrugnet/home"]:
return home.layout
elif pathname == "/covidrugnet/help":
return help.layout
elif pathname == "/covidrugnet/contacts":
return contacts.layout
elif pathname == "/covidrugnet/about":
return about.layout
elif pathname == "/covidrugnet/drug_target":
return drug_target.layout
elif pathname == "/covidrugnet/drug_projection":
return drug_projection.layout
elif pathname == "/covidrugnet/target_projection":
return target_projection.layout
# if pathname == "/target_disease":
# return target_disease.layout
# if pathname == "/target_interactors":
# return target_interactors.layout
else:
return error404.layout
## ---------- START ------------
if __name__ == "__main__":
print(
"Ready!\t(startup time: %sh %sm %ss)"
% tuple(str(timedelta(seconds=(time() - start_time))).split(":"))
) # print("\nReady!\t(startup time: %s)"%(datetime.datetime.now()-start_time))
print("Launcing on http://127.0.0.1:8050/covidrugnet\n\n")
import webbrowser
from threading import Timer
def openbrowser():
webbrowser.open("http://127.0.0.1:8050/covidrugnet")
Timer(1, openbrowser).start()
app.run_server(debug=False)
elif __name__ == "index":
# custom setting for deploying it with wsgi using from index import server as application (if setting a WSGIScriptAlias to /covidrugnet/)
app.config.update({"requests_pathname_prefix": "/covidrugnet/"})
print(
"Ready!\t(startup time: %sh %sm %ss)"
% tuple(str(timedelta(seconds=(time() - start_time))).split(":"))
) # print("Ready!\t(startup time: %s)\n"%(datetime.datetime.now()-start_time))