How to set an action for any value selected in the filter dropdown?


I’m trying to write an IF function that will trigger with any value of the dropdown.

This is the simplified code:

app.layout = html.Div(children=[
                dcc.Dropdown(id='dpdw_filter',  options=df['exam'].unique())])

    Output(component_id='fig_line', component_property='figure'),
    Input(component_id='dpdw_filter', component_property='value'))

def update_plot(selection):
     if selection is None:
            chart = px.line(data_frame = another_df ....

So, selection is None work fine when nothing is selected in the dropdown, now I want to change this code to the exactly opposite. I want the action to be trigger by any value of the dropdown.

if selection == value should work? For now I’m not able to make it work

Hello @tex.y,

Normally something like this:

if selection:
    ### code
1 Like

@jinnyzor Sorry my friend, but I didn’t understand.

code is not the source of the data used in the dropdown.

I edited the code for better clearance!

Replace ### code with the code that you want to execute when the value is not blank. :slight_smile:

1 Like

@jinnyzor oh boy… Now I get it !!!

Wait a minute, I will try

you nailed it

sorry for the basic question

1 Like

Haha, no worries.

It does get a little more complex when getting into dataframes. :wink: :smiley: