Skip to content

Commit c29c8cb

Browse files
committed
implemented live graphs
1 parent 8d1aadf commit c29c8cb

File tree

2 files changed

+43
-13
lines changed

2 files changed

+43
-13
lines changed

app.py

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,65 @@
11
import dash
22
import dash_core_components as dcc
33
import dash_html_components as html
4+
from dash.dependencies import Input, Output
45

56
app = dash.Dash()
67

8+
app.title = "Sorting Visualizer"
9+
10+
data = [2,6,4,7,8,4,5,7,8,9,4]
11+
712
app.layout = html.Div(children = [
8-
html.H1(children='Temporary Graph'),
13+
html.H1(children='Sorting Visualizer'),
14+
dcc.Input(id='input', value= 1, type='number'),
915
dcc.Graph(
10-
id='temp',
16+
id='graph',
1117
figure={
1218
'data': [
1319
{
14-
'x': [1,2,3,4,5],
15-
'y': [7,4,7,5,6],
16-
'type': 'line',
17-
'name': 'first graph'
18-
},
19-
{
20-
'x': [1, 2, 3, 4, 5],
21-
'y': [2, 6, 8, 3, 5],
20+
'y': data,
2221
'type': 'bar',
23-
'name': 'second graph'
22+
'name': 'first graph'
2423
}
2524
],
26-
25+
2726
'layout': {
28-
'title': 'First Web App Setup'
27+
'title': 'Visualization',
28+
'yaxis': {
29+
'range': [0, 1000]
30+
}
2931
}
3032
}
3133
)
3234
])
3335

36+
@app.callback(
37+
Output(component_id = 'graph', component_property='figure'),
38+
[Input(component_id='input', component_property='value')]
39+
)
40+
def updateValue(n):
41+
global data
42+
try:
43+
new_data = [ i*n for i in data]
44+
except Exception:
45+
new_data = [i for i in data]
46+
47+
return {
48+
'data': [
49+
{
50+
'y': new_data,
51+
'type': 'bar',
52+
'name': 'first graph'
53+
}
54+
],
55+
'layout': {
56+
'title': 'Visualization',
57+
'yaxis': {
58+
'range': [0, 1000]
59+
}
60+
}
61+
}
62+
63+
3464
if __name__ == '__main__':
3565
app.run_server(debug=True)

assets/favicon.ico

15 KB
Binary file not shown.

0 commit comments

Comments
 (0)