Need Help Using Radio Button to Update Graph on Dash

Hello,

I am close to solving a problem, but I can’t seem to get this over the hump. I am building a COVID19 dashboard in Plotly Dash and I want to have a metric plotted on a choropleth map update based on the selection of a radio button.

Below is a snippet of my code so far. The map will plot Cumulative Cases, but will not change once Cumulative Deaths is selected. Can anyone help me figure out what is not working here?


@app.callback(
    Output('choropleth_plot','figure'),
    Input('slider','value'),
    Input('radio1','value'))


def update_figure2(date_select_index,radio_select):
    date_select = slider_options.get(date_select_index, "1100-01-01")
    date_df = who_data[(who_data.Date_reported<=date_select)]  
    
    
    if 'Cumulative Cases' in radio_select:
        fig_test = px.choropleth_mapbox(date_df,
                                  geojson=geo_world_ok,
                                  locations='Country',
                                  color=date_df['count_color_cc'],
                                  color_continuous_scale='ylorrd',
                                  range_color=(0, date_df['count_color_cc'].max()),
                                  hover_name='Country',
                                  hover_data = {'count_color_cc':False,'Country':False,'Cumulative Cases':True},
                                  mapbox_style = 'open-street-map',
                                  zoom=1,
                                  center={'lat':19,'lon':11},
                                  opacity=0.6)
        fig_test.update_layout(
            margin={'r':0,'t':0,'l':0,'b':0},
            coloraxis_colorbar={
            'title':'Cumulative Cases',
            'tickvals': values_cc,
            'ticktext': ticks_cc})
        return fig_test


    elif 'Cumulative Deaths' in radio_select:
        fig_test = px.choropleth_mapbox(date_df,
                                  geojson=geo_world_ok,
                                  locations='Country',
                                  color=date_df['count_color_cd'],
                                  color_continuous_scale='ylorrd',
                                  range_color=(0, date_df['count_color_cd'].max()),
                                  hover_name='Country',
                                  hover_data = {'count_color_cd':False,'Country':False,'Cumulative Deaths':True},
                                  mapbox_style = 'open-street-map',
                                  zoom=1,
                                  center={'lat':19,'lon':11},
                                  opacity=0.6)

        fig_test.update_layout(
            margin={'r':0,'t':0,'l':0,'b':0},
            coloraxis_colorbar={
            'title':'Cumulative Deaths',
            'tickvals': values_cd,
            'ticktext': ticks_cd})
        return fig_test

I think this is somewhat related to the other question you’d asked few days ago :slight_smile:

Would you mind posting rest of your code as well just to make sure other variables you’re using in the callback are being set with appropriate values? Also it helps to know what type of objects the inputs and output really are.

I figured out! I change the line:

elif 'Cumulative Deaths' in radio_select:

to just

else:

and that seemed to do the trick!