-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvisualization_main.py
147 lines (116 loc) · 3.8 KB
/
visualization_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
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
"""
Program used for creating the React interface.
"""
from dash import Dash, dcc, html, Input, Output, callback, dash_table
import plotly.express as px
app = Dash(__name__, suppress_callback_exceptions=True)
from Functions import *
# Readed data
df2 = read_example_csv()
# d = {'Energy consumed': [1], 'Current energy': [3],'Current power': [3],'Current cost': [3]}
# Create a blant table
# create dataframe for total energy frame df3
d = {'Sensor name': ["robot1","robot2"], 'Type': ["robot","robot"],'State': [3,3],'Power': [4,4],'Total energy used today': [5,5],'Total cost today': [6,6]}
df3=pd.DataFrame(data=d)
app.layout = html.Div([
dcc.Location(id='url', refresh=False),
html.Div(id='page-content')
])
index_page = html.Div([
dcc.Link('Pie chart', href='/page-1'),
html.Br(),
dcc.Link('Line chart', href='/page-2'),
html.Br(),
dcc.Link('Table', href='/page-3'),
])
page_1_layout = html.Div([
html.H1('Page 1'),
dcc.Graph(
figure=px.pie(df2, values='Power', names='Machine')
),
html.Div(id='page-1-content'),
html.Br(),
dcc.Link('Go to Line chart', href='/page-2'),
html.Br(),
dcc.Link('Go back to home', href='/'),
])
@callback(Output('page-1-content', 'children'),
[Input('page-1-dropdown', 'value')])
def page_1_dropdown(value):
return f'You have selected {value}'
page_2_layout = html.Div([
html.H1('Page 2'),
# dcc.Graph(
# figure = px.line(df2, x=df2.index, y='Power', title='Time Series with Range Slider and Selectors')
# ),
dcc.Graph(
figure=dict(
data=[
dict(
x=df2.index,
y=df2['Power'].loc[df2['Machine'] == 'robot1'], # df.loc[df['column_name'] == some_value]
name='Robot 1',
marker=dict(
color='rgb(55, 83, 109)'
)
),
dict(
x=df2.index,
y=df2['Power'].loc[df2['Machine'] == 'robot2'], # df.loc[df['column_name'] == some_value]
name='Robot 2',
marker=dict(
color='rgb(26, 118, 255)'
)
)
],
layout=dict(
title='Robot Power',
showlegend=True,
legend=dict(
x=0,
y=1.0
),
margin=dict(l=40, r=0, t=40, b=30)
)
),
style={'height': 300},
id='my-graph'
),
html.Div(id='page-2-content'),
html.Br(),
dcc.Link('Go to Pie Chart', href='/page-1'),
html.Br(),
dcc.Link('Go back to home', href='/')
])
@callback(Output('page-2-content', 'children'),
[Input('page-2-radios', 'value')])
def page_2_radios(value):
return f'You have selected {value}'
page_3_layout = html.Div([
html.H1('Page 3'),
dash_table.DataTable(df3.to_dict('records'), [{"name": i, "id": i} for i in df3.columns]),
html.Div(id='page-3-content'),
html.Br(),
dcc.Link('Go to Line chart', href='/page-3'),
html.Br(),
dcc.Link('Go back to home', href='/'),
])
@callback(Output('page-3-content', 'children'),
[Input('page-3-dropdown', 'value')])
def page_3_dropdown(value):
return f'You have selected {value}'
# Update the index
@callback(Output('page-content', 'children'),
[Input('url', 'pathname')])
def display_page(pathname):
if pathname == '/page-1':
return page_1_layout
elif pathname == '/page-2':
return page_2_layout
elif pathname == '/page-3':
return page_3_layout
else:
return index_page
# You could also return a 404 "URL not found" page here
if __name__ == '__main__':
app.run_server(debug=True)