1

Can anyone let me know why my code is not updating the graph with data when I select drop-down value? (entire GitHub code in link in comments below)

def filterPollutants(selected_pollutants):
    if selected_pollutants:
        dff = df.loc[df.pollutant_abb.isin([selected_pollutants])]
    else:
        dff = df

    bar_fig = {
        "data": [
            go.Bar(
                x=dff["U_SAMPLE_DTTM"],
                y=dff["DISPLAYVALUE"],
            )
        ],
        "layout": go.Layout(
            title="Sampling for Local Limits",
            # yaxis_range=[0,2],
            yaxis_title_text="Metals mg/L",
        ),
    }
1

1 Answer 1

1

From testing the code at the Github link you shared I think the problem is in this line where you filter your data set in the callback:

dff = df.loc[df.pollutant_abb.isin([selected_pollutants])]

The problem with this line is that the value of selected_pollutants inside the callback is of the form ['SELECTED_VALUE_FROM_DROPDOWN'] and not 'SELECTED_VALUE_FROM_DROPDOWN'. This is because your dropdown has multi set to True.

But because of this your isin filter doesn't work, since you're essentially doing this:

dff = df.loc[df.pollutant_abb.isin([['SELECTED_VALUE_FROM_DROPDOWN']])]

instead of this:

dff = df.loc[df.pollutant_abb.isin(['SELECTED_VALUE_FROM_DROPDOWN'])]

So the fix could be to remove the list surrounding selected_pollutants:

dff = df.loc[df.pollutant_abb.isin(selected_pollutants)]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.