I am working on creating a dashboard that uses a range slider to filter a dropdown box.
Here is my code so far:
#Import packages
import dash
from dash import dcc, html
import dash_bootstrap_components as dbc
from dash.dependencies import Input, Output
letters = ['a','b','c','d','e','f','g','h','i','j']
dash_dict = {
1:'a',
2:'b',
3:'c',
4:'d',
5:'e',
6:'f',
7:'g',
8:'h',
9:'i',
10:'j'
}
app = dash.Dash()
server = app.server
app.layout = html.Div([
dbc.Row([
dbc.Col([
dcc.RangeSlider(
id='range_slider',
min=1,
max=10,
step=1,
value=[6, 10],
allowCross=False,
pushable=2,
tooltip={"placement": "bottom", "always_visible": True},
marks={
1: '1',
2: '2',
3: '3',
4: '4',
5: '5',
6: '6',
7: '7',
8: '8',
9: '9',
10: '10'
}
),
],width=6),
dbc.Col([
dcc.Dropdown(
id='dropdown',
style={'color':'black'},
options=[{'label': i, 'value': i} for i in letters],
)
],width=6)
])
])
#Configure dependent dropdown box from slider
@app.callback(
Output('dropdown', 'options'), #--> filter letters
Input('range_slider', 'value') #--> choose number range
)
def set_letter_options(selected_range):
return [{'label': i, 'value': i} for i in dash_dict[selected_range]],
if __name__=='__main__':
app.run_server()
I am following the chained callback example found here and was able to get this to work properly for a normal one-sided slider. However, with the range slider, I get an error that reads:
TypeError: unhashable type: 'list'
which makes sense, Iβm passing 2 values to slice and dice that dictionary up by. I am stuck on how to structure the callback to account for the dynamic range of the slider with the upper and lower bounds.
Can someone help point me in the right direction?
Thank you!