I am using plotly_chart to plot a graphic after selecting a value from selectbox, first run, it works as expected, but when i select a differnt value, the old graphic is still there, in gray mode

If you’re creating a debugging post, please include the following info:

  1. Are you running your app locally or is it deployed? [locally]

  2. If your app is deployed:
    a. Is it deployed on Community Cloud or another hosting platform?[local host]
    b. Share the link to the public deployed app.

  3. Share the link to your app’s public GitHub repository (including a requirements file).

  4. Share the full text of the error message (not a screenshot).

  5. Share the Streamlit and Python versions.[python 3.9 and Streamlit, version 1.37.1]

code looks like this:
        meas_ids = list(set(df_dict.keys()))
        meas_ids.sort()
        meas_id = st.selectbox('Static Measurement Selection?',meas_ids)
        df = df_dict[meas_id]
        #if df is not None:
        if st.button('Start') and df is not None:
            df = self._set_index(df)
            st.write(df)
            cols = df.columns.values.tolist()
            for col in [c for c in cols if c not in ['dn']]:
                df_col = df[['dn', col]]
                self._plot_samples(df_col, col)

def _plot_samples(self, df, col):
        group = df.groupby(['dn'])
        fig = go.Figure()         
        for k, v in group:
            if max(v[col]) > 0:
                name_str = str(k[0]) if isinstance(k, tuple) else k
                fig = fig.add_trace(go.Scatter(x=v.index, y=v[col], name=name_str))
        if fig.data:
            st.write('**{}**'.format(col))
            st.plotly_chart(fig)

Can you show how the plot looks in gray mode? I suspect it has something to do with plotting on the same figure object. Maybe clear the figure plotting once the selectionbox has changed?

the number of plotted graphic is not fixed, depending on the selectbox result, so for first selection with “M3”, it shows 2 graphic


then i select “B1” which should generate much more graphic and it shows below, not exactly gray, but uneditable, cleary should not be there, AvgCpuUsed is the first one, and it’s displayed below the staled graphic