-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
127 lines (111 loc) · 3.53 KB
/
app.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
# -*- coding: utf-8 -*-
"""
"""
__author__ = "Vegard Ulriksen Solberg"
__email__ = "[email protected]"
import datetime
import dash
from dash.dependencies import Output, Input, State
import dash_bootstrap_components as dbc
from solar_path.utils import SolarPath
from solar_path.items import (
create_date_sliders,
create_dropdown_mapstyles,
create_dropdown_timezones,
)
from dash import html
from dash import dcc
solar = SolarPath()
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.JOURNAL])
today = datetime.datetime.today()
layout = html.Div(
[
dbc.Row(dbc.Col(html.H1(id="header", children="Solar path"))),
dbc.Row(
dbc.Col(
html.P(id="info-text", children="Explore the suns path for a location")
)
),
html.Br(),
dbc.Row(
[
dbc.Col(
dbc.Input(
id="location-input",
type="text",
placeholder="Type address or city",
)
)
]
),
html.Br(),
dbc.Row(
[
dbc.Col(
dbc.Input(id="lat-input", type="number", placeholder="Latitude")
),
dbc.Col(
dbc.Input(id="lon-input", type="number", placeholder="Longitude")
),
dbc.Col(create_dropdown_mapstyles()),
dbc.Col(create_dropdown_timezones()),
dbc.Col(
dbc.Button(id="submit-button-state", n_clicks=0, children="Submit")
),
]
),
html.Br(),
dbc.Row(dbc.Col(dbc.Card(create_date_sliders(today.month, today.day), color="light", inverse=False))),
dcc.Graph(id="map-fig"),
dcc.Graph(id="sunrise-fig"),
dcc.Graph(id="analemma-fig"),
html.Br(),
html.Br(),
]
)
app.layout = dbc.Container(layout)
@app.callback(
Output("map-fig", "figure"),
[
Input("month-slider", "value"),
Input("day-slider", "value"),
Input("submit-button-state", "n_clicks"),
Input("dropdown-mapstyles", "value"),
Input("dropdown-timezones", "value"),
],
[
State("location-input", "value"),
State("lat-input", "value"),
State("lon-input", "value"),
],
)
def update_map_figure(month, day, button, map_style, timezone, location, lat, lon):
solar.update_attributes(lat, lon, location, timezone)
date = f"{today.year}.{month:0>2}.{day:0>2}"
return solar.create_map(date=date, map_style=map_style)
@app.callback(
Output("analemma-fig", "figure"),
[Input("submit-button-state", "n_clicks"), Input("dropdown-timezones", "value")],
[
State("location-input", "value"),
State("lat-input", "value"),
State("lon-input", "value"),
],
)
def update_analemma_figure(button, timezone, location, lat, lon):
solar.update_attributes(lat, lon, location, timezone)
return solar.analemma_figure()
@app.callback(
Output("sunrise-fig", "figure"),
[Input("submit-button-state", "n_clicks"), Input("dropdown-timezones", "value")],
[
State("location-input", "value"),
State("lat-input", "value"),
State("lon-input", "value"),
],
)
def update_sunrise_figure(button, timezone, location, lat, lon):
solar.update_attributes(lat, lon, location, timezone)
return solar.sunrise_figure()
if __name__ == "__main__":
app.run_server(port=8051, debug=True)