forked from radovankavicky/dash-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
140 lines (120 loc) · 4.08 KB
/
run.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import dash_html_components as html
import dash_core_components as dcc
import dash_table_experiments as dt
from dash.dependencies import Input, Output
from server import app, server
from tutorial import chapter_index
from tutorial import home
def create_contents(contents):
h = []
for i in contents:
if isinstance(i, list):
h.append(create_contents(i))
else:
h.append(html.Li(i))
return html.Ul(h)
chapters = {
'index': {
'url': '/',
'content': home.layout,
'name': 'Index',
'description': ''
}
}
chapters.update(chapter_index.chapters)
header = html.Div(
className='header',
children=html.Div(
className='container-width',
style={'height': '100%'},
children=[
html.A(html.Img(
src='https://cdn.rawgit.com/plotly/dash-docs/b1178b4e/images/dash-logo-stripe.svg',
className='logo'
), href='https://plot.ly/products/dash', className='logo-link'),
html.Div(className='links', children=[
html.A('pricing', className='link', href='https://plot.ly/dash/pricing'),
html.A('user guide', className='link active', href='/'),
html.A('plotly', className='link', href='https://plot.ly/'),
html.A(children=[html.I(className="fa fa-search")], className='link', href='/search')
])
]
)
)
app.title = 'Dash User Guide and Documentation - Dash by Plotly'
app.layout = html.Div(
[
header,
html.Div([
html.Div(id='wait-for-layout'),
html.Div([
html.Div(
html.Div(id='chapter', className='content'),
className='content-container'
),
], className='container-width')
], className='background'),
dcc.Location(id='location', refresh=False),
html.Div(dt.DataTable(rows=[{}]), style={'display': 'none'})
]
)
@app.callback(Output('chapter', 'children'),
[Input('location', 'pathname')])
def display_content(pathname):
if pathname is None:
return ''
if pathname.endswith('/') and pathname != '/':
pathname = pathname[:len(pathname) - 1]
matched = [c for c in chapters.keys()
if chapters[c]['url'] == pathname]
if matched and matched[0] != 'index':
if 'dash-deployment-server/' not in pathname:
content = html.Div([
html.Div(chapters[matched[0]]['content']),
html.Hr(),
dcc.Link(html.A('Back to the Table of Contents'), href='/'),
html.Div(id='wait-for-page-{}'.format(pathname)),
])
else:
content = html.Div([
html.Div(chapters[matched[0]]['content']),
html.Hr(),
dcc.Link(html.A('Back to Dash Deployment Server Documentation'), href='/dash-deployment-server'),
html.Div(id='wait-for-page-{}'.format(pathname)),
])
else:
content = chapters['index']['content']
return content
app.index_string = '''
<!DOCTYPE html>
<html>
<head>
{%metas%}
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta
name="description"
content="Dash User Guide and Documentation. Dash is a Python framework for building analytical web apps in Python."
>
<title>{%title%}</title>
{%favicon%}
{%css%}
<!-- Global site tag (gtag.js) - AdWords: 1009791370 -->
<script async src=""https://www.googletagmanager.com/gtag/js?id=AW-1009791370""></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'AW-1009791370');
</script>
</head>
<body>
{%app_entry%}
<footer>
{%config%}
{%scripts%}
</footer>
</body>
</html>
'''
if __name__ == '__main__':
app.run_server(debug=True, threaded=True, port=8050)