Skip to content

Instantly share code, notes, and snippets.

@techzeero
Last active March 2, 2022 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techzeero/af3f3f17cdc799344898102ddd7db5df to your computer and use it in GitHub Desktop.
Save techzeero/af3f3f17cdc799344898102ddd7db5df to your computer and use it in GitHub Desktop.
import dash
import dash_html_components as html
import dash_core_components as dcc
import plotly.express as px
from dash.dependencies import Input, Output
app = dash.Dash()
df = px.data.iris()
app.layout = html.Div([
html.H1(
id = 'H1',
children = 'Dash Ploty Basic',
style = {'textAlign':'center', 'marginTop':40,'marginBottom':40}
),
dcc.Dropdown(
id = 'dropdown',
options = [
{'label':'Setosa', 'value':'setosa' },
{'label': 'Versicolor', 'value':'versicolor'},
{'label': 'Virginica', 'value':'virginica'}
],
value = 'setosa'
),
dcc.Graph(id = 'graph')
])
@app.callback(Output(component_id='graph', component_property= 'figure'),
[Input(component_id='dropdown', component_property= 'value')])
def graph_update(dropdown_value):
fig = px.scatter(df[df["species"]==dropdown_value], x="sepal_width", y="sepal_length")
fig.update_layout(title = 'Sapel Length and Width of Different Species',
xaxis_title = 'Sepal Width',
yaxis_title = 'Sepal Length')
return fig
if __name__ == '__main__':
app.run_server()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment