-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart_dash.py
90 lines (78 loc) · 2.36 KB
/
start_dash.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
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
from flask_login import current_user
from arxiv_net.dashboard.pages import login, arxiv_dash
from arxiv_net.dashboard.server import app
header = html.Div(
className='header',
children=html.Div(
className='container-width',
style={'height': '100%'},
children=[
html.Img(
src='assets/dash-logo-stripe.svg',
className='logo'
),
html.Div(className='links', children=[
html.Div(id='user-name', className='link'),
html.Div(id='logout', className='link')
])
]
)
)
app.layout = html.Div(
[
header,
html.Div([
html.Div(
html.Div(id='page-content', className='content'),
className='content-container'
),
], className='container-width'),
dcc.Location(id='url', refresh=False),
html.Div(id='selected_paper', style={'display': 'none'})
]
)
@app.callback(
Output('page-content', 'children'),
[Input('url', 'pathname')])
def display_page(pathname):
if pathname == '/':
return login.layout
elif pathname == '/login':
return login.layout
elif pathname == '/success':
if current_user.is_authenticated:
return arxiv_dash.layout
else:
# 'No login page goes here'
return arxiv_dash.layout
# return login_fd.layout
# elif pathname == '/logout':
# if current_user.is_authenticated:
# logout_user()
# return logout.layout
# else:
# return logout.layout
else:
return '404'
@app.callback(
Output('user-name', 'children'),
[Input('page-content', 'children')])
def cur_user(input1):
if current_user.is_authenticated:
return html.Div('Username: ' + current_user.username)
# 'User authenticated' return username in get_id()
else:
return ''
@app.callback(
Output('logout', 'children'),
[Input('page-content', 'children')])
def user_logout(input1):
if current_user.is_authenticated:
return html.A('Logout', href='/logout')
else:
return ''
if __name__ == '__main__':
app.run_server(host='localhost', port=1337, debug=True)