Updating the graph display in plotly

Currently, when I use Streamlit to select a point on the graph.
It would be nice if the graph would refresh and the point you just selected would disappear.
Currently, however, new graphs are being added all the time.
I would like to fix this so that only one graph is updated at a time.
Please let me know if you can help me.
Thank you very much.

import pandas as pd
import plotly.express as px
import streamlit as st
from streamlit_plotly_events import plotly_events
import plotly.offline as offline
import plotly.graph_objects as go

df = pd.DataFrame({β€˜X’: [1, 2, 3, 4, 5, 6], β€˜Y’: [1, 2, 3, 4, 5, 6]})
df2 = pd.DataFrame({β€˜X’: [1, 2, 3, 4, 5, 6], β€˜Y’: [1, 2, 3, 4, 5, 6]})

aaa = st.checkbox(β€˜AAA’)
counter = 0

while aaa == True:
st.write(df)
key = β€œgraph_number” +’_’+ str(counter)
fig1 = px.scatter(df, x=β€˜X’, y=β€˜Y’,color_discrete_sequence=[β€œred”])
fig2 = px.line(df2,x=β€˜X’, y=β€˜Y’)
fig1.update_layout(clickmode=β€˜select’)
fig = go.Figure(data=fig1.data + fig2.data)
selected_points = plotly_events(
fig,
click_event = False,
select_event = True,
override_height = 500,
override_width = β€œ100%”,
key = key
)
try:
selected_points = eval(selected_points)
df_final = df.iloc[[v[β€˜pointIndex’] for v in selected_points]]
st.write(β€˜ζΆˆεŽ»γ™γ‚‹η‚Ήβ€™)
st.write(df_final)
st.write(β€˜ε‰Šι™€εΎŒβ€™)
df = df[~df[β€˜X’].isin(df_final[β€˜X’])]
counter = counter + 1
except:
break