Hello - new dash user here so hopefully forgive the (probably) easy question.
I am setting up a dynamic dropdown box based on options from a dataframe - I am looking to use the result from that dropdown and apply it to a previously defined function which would then produce the function’s result right below that dropdown menu.
Here is what I have:
import dash
from dash.exceptions import PreventUpdate
import dash_html_components as html
import dash_core_components as dcc
external_stylesheets = ["https://codepen.io/chriddyp/pen/bWLwgP.css"]
options = [
{"label": "New York City", "value": "NYC"},
{"label": "Montreal", "value": "MTL"},
{"label": "San Francisco", "value": "SF"},
]
def some_function(label)
print(label + " is a city")
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
app.layout = html.Div(
[
html.Label(["Single dynamic Dropdown", dcc.Dropdown(id="my-dynamic-dropdown")])
html.Div([some_function(id = "my-function')])
]
)
@app.callback(
dash.dependencies.Output("my-dynamic-dropdown", "options"),
dash.dependencies.Output("my-function"),
[dash.dependencies.Input("my-dynamic-dropdown", "search_value")],
)
def update_options(search_value):
if not search_value:
raise PreventUpdate
return [o for o in options if search_value in o["label"]]
if __name__ == "__main__":
app.run_server(debug=True)
Looking for a dropdown that will choose a value as the user starts typing, and then take that value and apply it to the function that I have created, resulting in the printout of (for example) ‘Montreal is a city’ directly underneath the dropdown box.
Unfortunately, while I don’t get any errors, it is not showing the printout of the function once I select the option from the dropdown.
1 post - 1 participant