forked from plotly/dash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelloworld.py
51 lines (45 loc) · 1.52 KB
/
helloworld.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
import pandas.io.data as web
from dash import Dash
from dash.components import div, h2, PlotlyGraph, Dropdown, label, Highlight
from datetime import datetime as dt
df = web.DataReader("aapl", 'yahoo', dt(2007, 10, 1), dt(2009, 4, 1))
dash = Dash(__name__)
dash.layout = div([
h2('hello dash'),
Highlight('import blah', className='python'),
div(className='row', content=[
div(className='two columns', content=[
div([
label('select x data'),
Dropdown(id='xdata', options=[{'val': c, 'label': c}
for c in df.columns])
]),
div([
label('select y data'),
Dropdown(id='ydata', options=[{'val': c, 'label': c}
for c in df.columns])
]),
]),
div(className='ten columns', content=[
PlotlyGraph(id='graph')
])
])
])
@dash.react('graph', ['xdata', 'ydata'])
def update_graph(xdata_dropdown, ydata_dropdown):
return {
'figure': {
'data': [{
'x': df[xdata_dropdown.selected],
'y': df[ydata_dropdown.selected],
'mode': 'markers'
}],
'layout': {
'xaxis': {'title': xdata_dropdown.selected},
'yaxis': {'title': ydata_dropdown.selected},
'margin': {'t': 0}
}
}
}
if __name__ == '__main__':
dash.server.run(port=8080, debug=True)