I have an address field and a dropdown where I intend to populate the autocomplete suggestions from mapbox API. In the callback, I pass the query string from input id='address_autocomplete'
. However, I am not seeing the values returned by the function population dropdown.
dbc.InputGroup(
[
dbc.InputGroupAddon("Property Address"),
dcc.Input(id='address_autocomplete'),
dcc.Dropdown(id='address_dropdown',style={'width':'60%'})
],
style={'margin-top':'30px', 'width': '53%', 'float': 'left'},
),
# Property address autocomplete
@app.callback(Output('address_dropdown', 'options'),
[Input('address_autocomplete', 'value')])
def autocomplete_address(value):
print(value)
addr = {}
# Call mapbox API and limit Autocomplete address suggestions
ret_obj = geocoder.forward(value, lon=-112.0913905, lat=33.4514652, limit=3)
response = ret_obj.json()
for i in range(len(response['features'])):
addr["res{}".format(i)] = response['features'][i]['place_name']
if value:
return [{'label': addr['res_0'], 'value': addr['res_0']},
{'label': addr['res_1'], 'value': addr['res_1']},
{'label': addr['res_2'], 'value': addr['res_2']}]
# Function call
r = geocoder.forward('Washington Park', lon=-112.0913905, lat=33.4514652, limit=3)
rj = r.json()
# Return
Washington Park, Phoenix, Arizona 85015, United States
Washington Park Playground, Phoenix, Arizona 85015, United States
Washington Park, Chicago, Illinois 60637, United States