Bring Drag & Drop to Dash with Dashboard Engine. 💫 Learn how at our next webinar!

I need a help with dash plotly graph not being updated with drop down list

# Connect the Plotly graphs with Dash Components
@app.callback(
    [Output(component_id='output_container', component_property='children'),
     Output(component_id='output-graph', component_property='figure')],
    [Input(component_id='slct_year', component_property='value')]
)
def update_graph(option_slctd):
    print(option_slctd)
    print(type(option_slctd))

    container = "The year chosen by user was: {}".format(option_slctd)
    dff = df2.copy()
    dff = dff[dff["Year_Reported"] == option_slctd]

# Plotly Express

#Plotly Graph Objects (GO)
    fig = go.Figure()
    stage_counter = 0
    for i in range(len(limits)):
      lim = limits[i]
      df_sub = df2[lim[0]:lim[1]]
      fig.add_trace(go.Scattergeo(
        lon = df_sub['long'],
        lat = df_sub['lat'],
        hovertext=df_sub[['CDP_Region','City','Scope1','Scope2','Scope3','TOTAL_Scope_1_2_3','Gases_Included','Change_in_emissions']],
        locationmode = 'ISO-3',
        customdata=df_sub[['CDP_Region','City','Scope1','Scope2','Scope3','TOTAL_Scope_1_2_3','Gases_Included','Change_in_emissions']],
        marker = dict(
            size = df_sub['TOTAL_Scope_1_2_3']*0.000002,
            color = colors[i],
            line_color='rgb(40,40,40)',
            line_width=0.5,
            sizemode='area'
        ),
        name = '{}'.format(stages[stage_counter])))
    stage_counter = stage_counter+1

    fig.update_geos(bgcolor= 'rgba(0,0,0,0)',
    showland=True,
    showcountries=True,countrycolor="#333300",projection_type="orthographic",oceancolor='#051D53',showocean=True,landcolor='#244804', showlakes=True, lakecolor='#0A3E63',
    showrivers=True, rivercolor="#2B3856")
    fig.update_layout(height=400,width=400,margin={"r":5,"t":0,"l":5,"b":0},paper_bgcolor='rgb(0,0,0)'
, plot_bgcolor='rgb(0,0,0)', geo=dict(bgcolor= 'rgba(0,0,0,0)'),font_color='white',colorscale_sequential='RdBu')


    fig.update_yaxes(visible=False, showticklabels=False)
    fig.update_xaxes(visible=False, showticklabels=False)
    fig.update_traces(
    hovertemplate="<br>".join([
        "CPD_Region: %{customdata[0]}",
        "City: %{customdata[1]}",
        "Scope1: %{customdata[2]}",
        "Scope2: %{customdata[3]}",
        "Scope3: %{customdata[4]}",
        "Total_Emissions: %{customdata[5]}",
        "Co2e: %{customdata[6]}",
        "Status: %{customdata[7]}"
    ])
)

           
           
    return container, fig


# ------------------------------------------------------------------------------

if __name__ == "__main__":
    app.run_server(debug=True)
serve(app.server, host="0.0.0.0", port=8050)

why does the scattergeo graph not updated with the drop down list values?
is it because of the forloop inside the graph?

Please I need your help!!!

HI @Ebtesam ,
welcome to the Dash community. We hope you’re enjoying the app-making process and we look forward to seeing you here a lot more.
It’s hard to pinpoint exactly what the problem is without seeing the full code, but was the original df2 dataframe used on purpose in this line below?

df_sub = df2[lim[0]:lim[1]]

Or, did you need to use dff?