I am trying to set up a simple Dash app that returns a value from a dataframe used as a "look-up table"; a screenshot of a sample test table is included here
Within the app, a user can enter one of many states (this is the first column in above table), and the app should return the corresponding two column entries from same row in which the state exists in this dataframe. For example: if a user selected LA, the app should return "med" and "radio"
Unfortunately, I am getting a call-back error after a user selection. My code is attached below. Can somebody please guide me on the way to resolve this? This is my first time using Dash - so appreciate any guidance!
app = dash.Dash(__name__)
server = app.server
df=pd.read_csv("test_lookup_table.csv", delimiter=',', encoding="utf-8-sig")
df.set_index('state')
app.layout = html.Div([
html.H1('On demand look up '),
html.H3('Select from list of states below'),
dcc.Dropdown(
id='dropdown',
options=[{'label': i, 'value': i} for i in df.state],
value='LALA'
),
html.Div(id='display-value')
])
@app.callback(
Output('dropdown','options'),
[Input('dropdown', 'value')])
def callback_a(i):
return df.loc[i, 1:3]
if __name__ == '__main__':
app.run_server(debug=True)