Hi all,
I just started learning the dash framework & would appreciate anyone who could help with my problem.
Problem:
I have a scatter plot between Profit & Sales based on Region in the United States & I’m trying to filter out the plot based on the region (Central, East, West, North). I’m successfully able to get the UI part of it but when I select a value in the drop-down, It doesn’t filter the dashboard - I’m having a hard time figuring out why?
Here’s my code:
import pandas as pd
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
data=pd.read_csv('/Users/harish/Downloads/Superstore.csv',sep=',')
data.head(10)
data.shape
data.columns
data.rename(columns={'Customer Name':'Customer_Name'})
data=data[(data.Sales<1000)]
data.Sales.max()
application=dash.Dash()
application.layout = html.Div([
html.Label('Multi-Select Dropdown'),
dcc.Dropdown(
id='Dropdown',
options=[
{'label': 'East', 'value': 'East'},
{'label':'West','value':'West'},
{'label':'Central','value':'Central'},
{'label':'South','value':'South'}
],
multi=True,
),
dcc.Graph(
id='Regionlevel-Profit&Sales',
figure={
'data': [
go.Scatter(
x=data[data['Region'] == i]['Sales'],
y=data[data['Region'] == i]['Profit'],
#text=df[df['Customer_Name'] == i]['Profit'],
mode='markers',
opacity=0.7,
marker={
'size': 5,
'line': {'width': 0.5, 'color': 'white'}
},
name=i
) for i in data.Region.unique()
],
'layout': go.Layout(
xaxis={'title': 'Sales'},
yaxis={'title': 'Profit'},
margin={'l': 50, 'b': 30, 't': 10, 'r': 0},
legend={'x': 0, 'y': 1},
hovermode='closest'
)
}
)
])
@application.callback(
dash.dependencies.Output('Dropdown','options'),
[dash.dependencies.Input('Dropdown', 'value')])
def callback_a(dropdown_value):
return 'You\'ve selected "{}"'.format(dropdown_value)
if __name__ == '__main__':
application.run_server()
Any help would be appreciated