-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdashTest.py
155 lines (133 loc) · 3.64 KB
/
dashTest.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 16 12:41:04 2021
@author: seolubuntu
"""
import dash
from dash import dcc
from dash import html
from dash import dash_table
from dash.dependencies import Input, Output
import dash_bootstrap_components as dbc
import plotly.express as px
from plotly.offline import plot
import pandas as pd
import numpy as np
import datetime as dt
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.SPACELAB])
# colors = {
# 'background': '#111111',
# 'text': '#7FDBFF'
# }
df = pd.DataFrame(
{
"Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
"Amount": [4, 1, 2, 2, 4, 5],
"City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"],
}
)
df2 = pd.DataFrame(
{
"Other": ["Some", "Data"],
"Table": ["More", "Data"],
}
)
fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")
longdata = np.random.randn(1000000)
longfig = px.line(x=np.arange(longdata.size), y=longdata)
longfig.update_yaxes(fixedrange=True)
table1 = dash_table.DataTable(
id="table",
columns=[{"name": i, "id": i} for i in df.columns],
data=df.to_dict("records"),
)
table2 = dash_table.DataTable(
id="table2",
columns=[{"name": i, "id": i} for i in df2.columns],
data=df2.to_dict("records"),
)
# use tabs for each table?
# use dbc layouts?
row = dbc.Row(
[
# Column 1
dbc.Col(dbc.Card(dbc.CardBody(dcc.Graph(id="example-graph-2", figure=fig)))),
# Column 2
dbc.Col(
dbc.Card(dbc.CardBody(dcc.Graph(id="example-graph-3", figure=longfig)))
),
]
)
navbar = dbc.NavbarSimple(
children=[
dbc.NavItem(dbc.NavLink("Page 1", href="#")),
dbc.DropdownMenu(
children=[
dbc.DropdownMenuItem("More pages", header=True),
dbc.DropdownMenuItem("Page 2", href="#"),
dbc.DropdownMenuItem("Page 3", href="#"),
],
nav=True,
in_navbar=True,
label="More",
),
],
brand="NavbarSimple",
brand_href="#",
)
app.layout = html.Div(
children=[
navbar,
html.H1(
children="Hello Dash",
style={
"textAlign": "center",
# 'color': colors['text']
},
),
html.Div(
children="Dash: A web application framework for Python.",
style={
"textAlign": "center",
# 'color': colors['text']
},
),
row,
dbc.Tabs([dbc.Tab(table1, label="Tab 1"), dbc.Tab(table2, label="Tab 2")]),
html.Div(
id="update-text",
# style = {'color': colors['text']}
),
html.Div(
id="update-text-slow",
# style = {'color': colors['text']}
),
dcc.Interval(id="interval-component", interval=500, n_intervals=0), # in ms
dcc.Interval(
id="slow-interval-component", interval=5000, n_intervals=0 # in ms
),
]
)
@app.callback(
Output("update-text-slow", "children"),
Input("slow-interval-component", "n_intervals"),
)
def update_text(n):
return [
html.Span(
"(Slow) Time Now: %.6f\nIntervals: %d"
% (dt.datetime.utcnow().timestamp(), n)
)
]
@app.callback(
Output("update-text", "children"), Input("interval-component", "n_intervals")
)
def update_text(n):
return [
html.Span(
"Time Now: %.6f\nIntervals: %d" % (dt.datetime.utcnow().timestamp(), n)
)
]
if __name__ == "__main__":
app.run_server(debug=True)