-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·66 lines (57 loc) · 2.21 KB
/
main.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
from dash import Dash
from dash_bootstrap_components.themes import DARKLY
from flask_caching import Cache
import src.callbacks.button_loading
import src.callbacks.children as children
import src.callbacks.clean_table as clean_table
import src.callbacks.create_dropdown as create_dropdown
import src.callbacks.daily_api_requests as daily_api_requests
import src.callbacks.modals as modals
import src.callbacks.monthly_api_requests as monthly_api_requests
import src.callbacks.quarterly_api_requests as quarterly_api_requests
import src.callbacks.theme_toggle
import src.components.layout as layout
try:
import my_config as config
except ImportError:
import config
dbc_css = "https://cdn.jsdelivr.net/gh/AnnMarieW/dash-bootstrap-templates/dbc.min.css"
# Instantiate the dash app.
app = Dash(
__name__,
external_stylesheets=[DARKLY, dbc_css],
serve_locally=config.LOCALLY_STYLE,
suppress_callback_exceptions=config.CALLBACK_SUPPRESS,
title='Economic Data App',
update_title='Loading...'
)
# Name the webserver object. This is passed to the wsgi and flask-cache.
server = app.server
# Instantiate the flask cache
if config.CACHE_TYPE == 'redis':
cache = Cache(config={
'CACHE_TYPE': 'RedisCache',
'CACHE_REDIS_HOST': config.REDIS_HOST,
'CACHE_REDIS_PORT': config.REDIS_PORT
})
elif config.CACHE_TYPE == 'files':
cache = Cache(config={
'CACHE_TYPE': 'FileSystemCache',
'CACHE_DIR': config.CACHE_DIRECTORY,
'CACHE_THRESHOLD': config.CACHE_SIZE,
'CACHE_OPTIONS': config.PERMISSIONS
})
cache.init_app(app.server)
# Provide the layout, containing all the dash components to be displayed.
app.layout = layout.create_layout()
# Instantiate the imported callbacks. The clientside callbacks are instantiated via module import.
modals.modal_callbacks(app)
children.notification_callback(app)
daily_api_requests.daily_callback(app)
monthly_api_requests.monthly_callback(app)
quarterly_api_requests.quarterly_callback(app)
create_dropdown.table_dropdown_callback(app)
clean_table.table_cleaning_callback(app)
# Deploys the app locally if run_locally is True.
if __name__ == '__main__' and config.RUN_LOCALLY:
app.run(debug=config.DEBUG_BOOL, port=config.PORT_NUMBER)