Hi @matt.sd.watson.
Difficult to tell what’s going on but the shapes are part of the figure object. If you update your figure via a callback, the shapes should be erased.
from dash import Dash, dcc, html, Input, Output, Patch
import dash_bootstrap_components as dbc
from dash.exceptions import PreventUpdate
import plotly.graph_objects as go
import numpy as np
# prepare trace data
data = go.Scatter(
x=[1, 10],
y=[1, 10],
mode='markers',
marker={
'size': 8,
'symbol': 'circle-open',
},
)
# create figure
fig = go.Figure(data=data)
# update layout
fig.update_layout(
template='plotly_dark',
plot_bgcolor='rgba(0, 0, 0, 0)',
paper_bgcolor='rgba(0, 0, 0, 0)',
width=700,
height=500,
margin={
'l': 0,
'r': 0,
't': 20,
'b': 100,
}
)
# add some shapes
for i in range(1, 6):
fig.add_shape(
{
'type': 'rect',
'x0': np.random.randint(1, 5), 'x1': np.random.randint(6, 11),
'y0': np.random.randint(1, 5), 'y1': np.random.randint(6, 11),
},
editable=True,
name=f'shape_{i}',
line={
'color': ['red', 'yellow', 'blue', 'pink'][np.random.randint(0, 4)],
'width': 2,
'dash': 'solid'
},
)
# Build App
app = Dash(
__name__,
external_stylesheets=[dbc.themes.SLATE],
meta_tags=[
{
'name': 'viewport',
'content': 'width=device-width, initial-scale=1.0'
}
]
)
# app layout
app.layout = dbc.Container(
[
dbc.Row(
dbc.Col(
dcc.Graph(
id='graph',
figure=fig,
config={
'scrollZoom': True,
'displayModeBar': False,
}
),
width={'size': 5, 'offset': 0}
), justify='around'
),
dbc.Row(
[
dbc.Col(html.H5('Click button to delete shapes')),
]
),
dbc.Row(
[
dbc.Col(
html.Button(
'Delete',
id='delete'
),
)
], justify='around'
)
], fluid=True
)
@app.callback(
Output('graph', 'figure'),
Input('delete', 'n_clicks'),
)
def get_click(click):
if not click:
raise PreventUpdate
else:
# delete shapes
patched = Patch()
patched['layout']['shapes'] = []
return patched
if __name__ == '__main__':
app.run(debug=True, port=8053)