-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathdash_simple_app_2.py
More file actions
43 lines (35 loc) · 1.08 KB
/
dash_simple_app_2.py
File metadata and controls
43 lines (35 loc) · 1.08 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
from pathlib import Path
import pandas as pd
from dash import Dash, html, dcc, Input, Output
import plotly.express as px
app = Dash(__name__)
src_file = Path.cwd() / "data" / "raw" / "EPA_fuel_economy_summary.csv"
df = pd.read_csv(src_file)
fuel_types = df["fuel_type_summary"].unique()
app.layout = html.Div(
children=[
html.H1("Simple Histogram"),
html.Div("Annual Fuel Cost Plot."),
dcc.Graph(id="histogram"),
dcc.Dropdown(
id="fuel_id",
options=[{"label": i, "value": i} for i in fuel_types],
value=[i for i in fuel_types],
multi=True,
),
]
)
@app.callback(Output("histogram", "figure"), Input("fuel_id", "value"))
def update_output(fuel_list):
filtered_df = df[df["fuel_type_summary"].isin(fuel_list)]
fig = px.histogram(
filtered_df,
x="fuelCost08",
color="class_summary",
labels={"fuelCost08": "Annual Fuel Cost"},
nbins=40,
title="Fuel Cost Distribution",
)
return fig
if __name__ == "__main__":
app.run_server(debug=True)