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
| import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.graph_objs as go
from plotly import tools
import datetime
import pandas as pd
import time
from datetime import datetime as dt
app = dash.Dash(__name__)
server = app.server # the Flask app
app.layout = html.Div([
dcc.Dropdown(
id='dropdown',
options=[
{'label': 'Possession','value': 'POSS'},
{'label': 'SainteMarie','value': 'MASM'},
{'label': 'NosyBe','value': 'MANB'},
],
value='MASM'
),
dcc.DatePickerRange(
id='my-date-picker-range',
min_date_allowed=dt(2019, 8, 5),
max_date_allowed=dt(2022, 9, 19),
initial_visible_month=dt(2019, 8, 5),
end_date=dt(2018, 8, 25)),
#html.Div(id='display-value'),
#html.Div(id='update-value'),
#html.Div(id='update-value'),
dcc.Graph(id='update-value',
figure={"layout": {
"title": "My Dash Graph",
"height": 1000, # px
"width": 1000, # px
}})
])
@app.callback(dash.dependencies.Output('update-value', 'figure'),
[dash.dependencies.Input('dropdown', 'value'),
dash.dependencies.Input('my-date-picker-range', 'start_date'),
dash.dependencies.Input('my-date-picker-range', 'end_date')])
#def display_value(value):
# return 'You have selected "{}"'.format(value)
def update_value(value,start_date,end_date):
df = pd.read_csv(value+'.csv')
print("coucou",value+'.csv')
print("start",start_date)
#x1=df['dateTime']
x2= pd.to_datetime(df['dateTime'],unit='s')
y1=df['outTemp']
y2=df['barometer']
y3=df['rain']
y4=df['rainRate']
y5=df['windSpeed']
trace1 = go.Scatter(x=x2,y=y1,yaxis='y1',xaxis='x1',)
trace2 = go.Scatter(x=x2,y=y2,yaxis='y2',xaxis='x2')
trace3 = go.Scatter(x=x2,y=y3,yaxis='y3',xaxis='x3')
trace4 = go.Scatter(x=x2,y=y4,yaxis='y4',xaxis='x4')
trace5 = go.Scatter(x=x2,y=y5,yaxis='y5',xaxis='x5')
fig = tools.make_subplots(rows=4, cols=1,shared_xaxes=True,
specs=[[{"secondary_y": True}], [{"secondary_y": True}],
[{"secondary_y": True}], [{"secondary_y": True}]])
fig.append_trace(trace1, 1, 1)
fig.append_trace(trace2, 2, 1)
fig.append_trace(trace3, 3, 1)
fig.append_trace(trace4, 3, 1)
fig.append_trace(trace5, 4, 1)
fig['layout'].update(title='Please wait for data retrieving,can be long (up to 1mn)')
fig.update_layout(xaxis_range=[start_date,end_date])
# fig["layout"]["yaxis1"].update(anchor = "x2", side = "left")
# fig["layout"]["yaxis2"].update(anchor = "x2", side = "left")
# fig["layout"]["yaxis3"].update(anchor = "x2", side = "left")
# fig["layout"]["yaxis4"].update(range = [0, 0.5],anchor = "x2", side = "right",overlaying = 'y3')
# fig["layout"]["yaxis5"].update(anchor = "x2", side = "left")
layout = go.Layout(
yaxis3=dict(
side='left',
title='yaxis5 title',
anchor='x3'
),
yaxis4=dict(
overlaying='y3',
side='right',
anchor='x3'
),)
test= go.Figure(data=fig,layout=layout)
return test
if __name__ == '__main__':
app.run_server(host='0.0.0.0',port=8050) |
Partager