Created
October 19, 2020 12:52
-
-
Save chyld/8d7a3026e5f33d9061f1460436cd1b0a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dash | |
import dash_core_components as dcc | |
import dash_html_components as html | |
from dash.dependencies import Input, Output | |
import plotly.express as px | |
import pandas as pd | |
# ----------------------------------------------------------------------------------------------- # | |
# ----------------------------------------------------------------------------------------------- # | |
# ----------------------------------------------------------------------------------------------- # | |
df = pd.read_csv('https://raw.githubusercontent.com/chyld/datasets/main/auto-mpg.csv') | |
cols = df.columns | |
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] | |
app = dash.Dash(__name__, external_stylesheets=external_stylesheets) | |
# ----------------------------------------------------------------------------------------------- # | |
# ----------------------------------------------------------------------------------------------- # | |
# ----------------------------------------------------------------------------------------------- # | |
app.layout = html.Div([ | |
html.H1('Auto Dashboard'), | |
html.Img(src="https://www.motortrend.com/uploads/sites/5/2015/04/quickest-30-mpg-vehicles.jpg", | |
style={'width': '350px'}), | |
html.Br(), | |
html.A('Google', href="http://google.com", target="_blank"), | |
dcc.Dropdown( | |
id='features', | |
options=[{'label': c, 'value': c} for c in cols], | |
value='mpg' | |
), | |
dcc.Graph(id='histogram', style={ | |
'border': '3px solid black', | |
'marginBottom': '100px', 'width': '700px' | |
}) | |
]) | |
# ----------------------------------------------------------------------------------------------- # | |
# ----------------------------------------------------------------------------------------------- # | |
# ----------------------------------------------------------------------------------------------- # | |
@app.callback( | |
Output('histogram', 'figure'), | |
[Input('features', 'value')]) | |
def update_figure(feature): | |
series = df[feature] | |
title = f"Histogram of {feature}" | |
fig = px.histogram(series, histnorm='probability density', title=title) | |
return fig | |
# ----------------------------------------------------------------------------------------------- # | |
# ----------------------------------------------------------------------------------------------- # | |
# ----------------------------------------------------------------------------------------------- # | |
if __name__ == '__main__': | |
app.run_server(debug=True, port=4444) | |
# ----------------------------------------------------------------------------------------------- # | |
# ----------------------------------------------------------------------------------------------- # | |
# ----------------------------------------------------------------------------------------------- # |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment