mattritchey commited on
Commit
e4753f6
·
1 Parent(s): 1f70619

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Created on Wed Jul 26 14:46:06 2023
3
+
4
+ @author: mritchey
5
+ """
6
+
7
+ # Import packages
8
+ from dash import Dash, html, dash_table, dcc, callback, Output, Input
9
+ import pandas as pd
10
+ import plotly.express as px
11
+
12
+ # Incorporate data
13
+ df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminder2007.csv')
14
+
15
+ # Initialize the app
16
+ app = Dash(__name__)
17
+
18
+ # App layout
19
+ app.layout = html.Div([
20
+ html.Div(children='My First App with Data, Graph, and Controls'),
21
+ html.Hr(),
22
+ dcc.RadioItems(options=['pop', 'lifeExp', 'gdpPercap'], value='lifeExp', id='controls-and-radio-item'),
23
+ dash_table.DataTable(data=df.to_dict('records'), page_size=20),
24
+ dcc.Graph(figure={}, id='controls-and-graph')
25
+ ])
26
+
27
+ # Add controls to build the interaction
28
+ @callback(
29
+ Output(component_id='controls-and-graph', component_property='figure'),
30
+ Input(component_id='controls-and-radio-item', component_property='value')
31
+ )
32
+ def update_graph(col_chosen):
33
+ fig = px.histogram(df, x='continent', y=col_chosen, histfunc='avg')
34
+ return fig
35
+
36
+ # Run the app
37
+ if __name__ == '__main__':
38
+ app.run(debug=True)