-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion3.py
More file actions
72 lines (66 loc) · 1.9 KB
/
version3.py
File metadata and controls
72 lines (66 loc) · 1.9 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
import dash
import dash_html_components as html
import dash_core_components as dcc
import plotly.graph_objects as go
import plotly.express as px
import pandas as pd
# Chargement du jeu de données
df = pd.read_csv('https://drive.google.com/uc?export=download&id=1N3FclyWK0Hnpqla-MEbZy9KejVzNuf8V')
scattergeo = go.Scattergeo(
lat=df['Latitude'],
lon=df['Longitude'],
marker=dict(color='red')
)
# Initialisation de l'application Dash
app = dash.Dash()
# Définition du layout de l'application
app.layout = html.Div([
# Titre du tableau de bord
html.H1('Tableau de bord avec Plotly Dash'),
# Frise temporelle
dcc.RangeSlider(
id='year-slider',
min=df['Year'].min(),
max=df['Year'].max(),
value=[df['Year'].min(), df['Year'].max()],
marks={str(year): str(year) for year in df['Year'].unique()},
step=None
),
# Graphique à barres
dcc.Graph(
id='histogram'
),
# Graphique de carte
dcc.Graph(
id='map',
figure={
'data': [scattergeo],
'layout': {
'geo': {
'projection': 'natural earth',
'center': {'lat': 46.2276, 'lon': 2.2137},
}
}
}
)
])
@app.callback(
[dash.dependencies.Output('histogram', 'figure')],
[dash.dependencies.Input('year-slider', 'value')],
)
def update_histogram(year_range):
# Filtrage des données en fonction de la sélection de l'utilisateur sur la frise temporelle
filtered_df = df[(df['Year'] >= year_range[0]) & (df['Year'] <= year_range[1])]
# Création du graphique
figure = {
'data': [
{'x': filtered_df['Year'], 'y': filtered_df.groupby('Year').size(), 'type': 'bar'},
],
'layout': {
'title': 'Nombre de séismes par année'
}
}
return figure,
# Exécution de l'application
if __name__ == '__main__':
app.run_server(debug=True)