HuguesHPI commited on
Commit
bdfb86d
1 Parent(s): 241b2f9

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import dash
2
+ import dash_core_components as dcc
3
+ import dash_html_components as html
4
+ from dash.dependencies import Input, Output
5
+ import plotly.express as px
6
+ import pandas as pd
7
+ from sklearn import datasets
8
+
9
+ iris = datasets.load_iris()
10
+ df_iris = pd.DataFrame(iris.data, columns=iris.feature_names)
11
+ df_iris['species'] = pd.Categorical.from_codes(iris.target, iris.target_names)
12
+
13
+ app = dash.Dash(__name__)
14
+
15
+ # Layout de l'application
16
+ app.layout = html.Div([
17
+ html.H1("Graphique en Violon du Dataset Iris"),
18
+ dcc.Dropdown(
19
+ id='feature-selected',
20
+ options=[{'label': i, 'value': i} for i in df_iris.columns[:-1]],
21
+ value='sepal length (cm)'
22
+ ),
23
+ dcc.Graph(id='violin-plot')
24
+ ])
25
+
26
+ # Callback pour mettre à jour le graphique
27
+ @app.callback(
28
+ Output('violin-plot', 'figure'),
29
+ [Input('feature-selected', 'value')]
30
+ )
31
+ def update_graph(selected_feature):
32
+ fig = px.violin(df_iris, y=selected_feature, color='species', box=True, points="all")
33
+ return fig
34
+
35
+ # Exécution de l'application
36
+ if __name__ == '__main__':
37
+ app.run_server(debug=True)