0

I have three inputs for my map in the plotly dash and I want to use px.scatter_mapbox as the map type. Meanwhile, the data has three categorical columns, including 'region', 'country' and 'status', with one metric column of '4/24/20'. These three dimensions are multiple dropdown which I think they have no problem (normal to show up). The problem is the callback below. It is always showing the error of 'Lengths must compare to match'. I am totally lost.

@app.callback(
    Output('map-graph', 'figure'),
    [Input('region_dropdown_id', 'value'),
     Input('country_dropdown_id', 'value'),
     Input('status_dropdown_id', 'value')
     ],
)
def map_selection(input1, input2, input3):
    import plotly.express as px
    MBToken = 'your token'
    px.set_mapbox_access_token(MBToken)
    dff = df
    dff = dff[dff["4/24/20"]>0]
    filtered_df = dff[(dff['region'] == input1) & (dff['country'] == input2) & (dff['status'] == input3)]
    fig = px.scatter_mapbox(filtered_df, lat="Lat", lon="Long",     color= input3, size="4/24/20",
                      color_continuous_scale=px.colors.cyclical.IceFire, size_max=100, zoom=0)
    return fig

enter image description here

1 Answer 1

1

It looks like you are using multi-value dropdown Dash components so their 'value' attributes are actually Python lists rather than individual values.

The following modification to your code should hopefully fix the error:

filtered_df = dff[(dff['region'] == input1[0]) & (dff['country'] == input2[0]) & (dff['status'] == input3[0])]

But this obviously assumes you will only ever be selecting one value in the multi-value dropdowns. If that is your intention you might consider changing these to a different type of dropdown. They are all listed here. Hope that helps!

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.