-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDashboard.py
More file actions
158 lines (141 loc) · 4.94 KB
/
Dashboard.py
File metadata and controls
158 lines (141 loc) · 4.94 KB
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
156
157
158
import dash
from dash import dcc
from dash import html
from dash.dependencies import Input, Output
import plotly.express as px
import pandas as pd
import numpy as np
import plotly.graph_objs as go
df = pd.read_csv('weather1.csv')
df1 = df.iloc[np.r_[0:40, -40:0]]
countries=df["Station_State"].unique()
df2 = pd.read_csv('Mean_Temp.csv')
df2 = df2.set_index('YEAR')
time_durations = df2.columns
app = dash.Dash(__name__)
app.layout = html.Div(style={'background-image': 'url(https://image.freepik.com/free-vector/white-abstract-background_23-2148810113.jpg'},children=[
html.Hr(),
html.Div([html.H1(children='WEATHER ANALYSIS DASHBOARD',style={'textAlign': 'center','fontSize':40,'color': 'red'})]),
html.Hr(),
html.Div([
html.Div([
html.H1(children='PIE CHART',style={'textAlign': 'center','fontSize':35}),
html.P("Names:",style={'fontSize':23}),
dcc.RadioItems(
id='names',
options=[{'value': x, 'label': x}
for x in ['Date_Year', 'Station_State']],
value='Date_Year',
labelStyle={'display': 'inline-block'}
),
html.P("Values:",style={'fontSize':23}),
dcc.RadioItems(
id='values',
options=[{'value': x, 'label': x}
for x in ['Data_Temperature_Avg_Temp', 'Data_Wind_Speed']],
value='Data_Temperature_Avg_Temp',
),
dcc.Graph(id="pie-chart"),],className ='six columns'),
html.Hr(),
html.Hr(),
html.Br(),
html.Div([
html.H1(children='SCATTER PLOT--WIND SPEED Vs AVERAGE TEMPERATURE',style={'textAlign': 'center','fontSize':35}),
dcc.Graph(id="scatter-plot"),
html.P("Average Temperature:",style={'fontSize':25}),
dcc.RangeSlider(
id='range-slider',
min=0, max=100, step=1,
marks={10: '10', 100: '100'},
value=[20, 30]
),
], className='six columns'),
], className='row'),
html.Br(),
html.Hr(),
html.Div([
html.Hr(),
html.H1(children='BAR CHART--DATE Vs AVERAGE TEMPERATURE',style={'textAlign': 'center','fontSize':35}),
dcc.Dropdown(
id="dropdown",
options=[{"label": x, "value": x} for x in countries],
value=countries[0],
clearable=False
),
dcc.Graph(id="bar-chart"),
], className='row'),
html.Div([
html.Hr(),
html.Hr(),
html.Br(),
html.H1(children='AVERAGE TEMPERATURE ANALYSIS',style={'textAlign': 'center','fontSize':35}),
html.Div([
html.Div([
dcc.Dropdown(
id='time_durs',
options=[{'label': i, 'value': i}
for i in time_durations],
value='ANNUAL',
placeholder='Select Month/time duration'
)
],
style={'width': '48%', 'display': 'inline-block'})
]),
dcc.Graph(id='indicator-graphic'),
], className='row'),
])
@app.callback(
Output("pie-chart", "figure"),
[Input("names", "value"),
Input("values", "value")])
def generate_chart(names, values):
fig = px.pie(df1, values=values, names=names)
return fig
@app.callback(
Output("scatter-plot", "figure"),
[Input("range-slider", "value")])
def update_scatter_plot(slider_range):
low, high = slider_range
mask = (df['Data_Temperature_Min_Temp'] > low) & (df['Data_Temperature_Max_Temp'] < high)
fig = px.scatter(
df[mask], x="Data_Wind_Speed", y="Data_Temperature_Avg_Temp",
color="Station_State", size='Data_Wind_Direction')
return fig
@app.callback(
Output("bar-chart", "figure"),
[Input("dropdown", "value")])
def update_bar_chart(Station_State):
mask = df["Station_State"] == Station_State
fig = px.bar(df[mask], x="Date_Full", y="Data_Temperature_Avg_Temp",color="Date_Month",barmode="group")
return fig
@app.callback(
Output('indicator-graphic', 'figure'),
[Input('time_durs', 'value')])
def update_graph(month):
dff = df2[month]
dff_roll = dff.rolling(20, min_periods=5).mean()
return {
'data': [go.Scatter(
x=list(dff.index),
y=dff.values,
name='Temprature',
mode='lines+markers'
), go.Scatter(
x=list(dff_roll.index),
y=dff_roll.values,
name='Rolling Mean',
mode='lines+markers'
)],
'layout': {
'height': 525,
'margin': {'l': 20, 'b': 30, 'r': 10, 't': 10},
'annotations': [{
'x': 0, 'y': 0.85, 'xanchor': 'left', 'yanchor': 'bottom',
'xref': 'paper', 'yref': 'paper', 'showarrow': False,
'align': 'left', 'bgcolor': 'rgba(255, 255, 255, 0.5)'
}],
'yaxis': {'type': 'linear'},
'xaxis': {'showgrid': False}
}
}
app.run_server(debug=True)