# How to get current active Shape?

**URL:** <https://community.plotly.com/t/how-to-get-current-active-shape/42235>\
**Category:** 📊 Plotly Python\
**Created:** [July 9, 2020, 4:21pm UTC](https://community.plotly.com/t/how-to-get-current-active-shape/42235 "2020-07-09T16:21:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sweetdream](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@sweetdream](https://community.plotly.com/u/sweetdream)\
**Post date:** [July 9, 2020, 4:21pm UTC](https://community.plotly.com/t/how-to-get-current-active-shape/42235/1 "2020-07-09T16:21:25Z")

</div>

Hello,

Does someone know **how to programmatically know which editable shape is currently activated**?

I would like to allow the user to delete the selected shape by clicking a button. The only way found, was by forcing the user to first move the shape (the fillcolor is changed to red using the “on\_change” callback). Then, I can detect the Red shape and delete it.  
My approach is not elegant and apparently, the callback “on\_change” is lost after the first click on the button (probably because the way I use to delete the shape but I haven’t found any proposal in the documentation)

Any help is more than welcome !

Patrick

```auto
import plotly.graph_objects as go
from ipywidgets import Button, VBox
fig = go.FigureWidget()

# Set axes properties
fig.update_xaxes(range=[0, 7], showgrid=False)
fig.update_yaxes(range=[0, 3.5])

shp1 = go.layout.Shape(
    type="rect",
    x0=1,
    y0=1,
    x1=2,
    y1=3,
    fillcolor="Blue",
    editable=True)

shp2 = go.layout.Shape(
    type="rect",
    x0=3,
    y0=1,
    x1=6,
    y1=2,
    fillcolor="Blue",
    editable=True)

# Add shapes
fig.add_shape(shp1)
fig.add_shape(shp2)
fig.update_shapes(dict(xref='x', yref='y'))

def change_color(shp,*args,**kwargs):
    shp.update(dict(fillcolor='Red'))

def delete_shapes(*args,**kwargs):
    with output:
        try:
            list_shapes=[shp for shp in fig.layout.shapes if shp.fillcolor!='Red']
            self.fig.update_layout(shapes=list_shapes)
        except Exception as e:
            raise e
        
        
for shp in fig.layout.shapes:
    shp.on_change(change_color,'x0','y0','x1','y1')

button.on_click(delete_shapes)
VBox([button,fig])

```

---

<div class="post-metadata">

**Author:** ![smalgotrader](https://avatars.discourse-cdn.com/v4/letter/s/bcef8e/32.png) [@smalgotrader](https://community.plotly.com/u/smalgotrader)\
**Post date:** [January 17, 2021, 1:33pm UTC](https://community.plotly.com/t/how-to-get-current-active-shape/42235/2 "2021-01-17T13:33:29Z")

</div>

Did you find an elegant solution to do this? I am looking to do the same.

Thanks in advance  
SM

---

<div class="post-metadata">

**Author:** ![sweetdream](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@sweetdream](https://community.plotly.com/u/sweetdream)\
**Post date:** [January 17, 2021, 11:22pm UTC](https://community.plotly.com/t/how-to-get-current-active-shape/42235/3 "2021-01-17T23:22:37Z")

</div>

Unfortunately no ☹

---

<div class="post-metadata">

**Author:** ![SkyTemple](https://avatars.discourse-cdn.com/v4/letter/s/e19adc/32.png) [@SkyTemple](https://community.plotly.com/u/SkyTemple)\
**Post date:** [April 20, 2022, 12:04am UTC](https://community.plotly.com/t/how-to-get-current-active-shape/42235/4 "2022-04-20T00:04:45Z")

</div>

Really wish that selecting a Shape would generate a relayoutData or selectedData callback.

In fact, needing this so badly I am willing to implement it myself.

Problem being, I do not know where I would begin to implement it in the source code.

Can anyone help with this?

---

<div class="post-metadata">

**Author:** ![jorge243](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jorge243/32/6269_2.png) [@jorge243](https://community.plotly.com/u/jorge243)\
**Post date:** [January 19, 2024, 8:02pm UTC](https://community.plotly.com/t/how-to-get-current-active-shape/42235/5 "2024-01-19T20:02:27Z")

</div>

Hi! Still no solution for this? @adamschroeder having this feature would be great!

---

<div class="post-metadata">

**Author:** ![adamschroeder](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/adamschroeder/32/17280_2.png) [@adamschroeder](https://community.plotly.com/u/adamschroeder)\
**Post date:** [January 19, 2024, 9:50pm UTC](https://community.plotly.com/t/how-to-get-current-active-shape/42235/6 "2024-01-19T21:50:40Z")

</div>

@jorge243  
Would you be willing to open a new issue regarding this topic in our GitHub repo?

---

<div class="post-metadata">

**Author:** ![jorge243](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jorge243/32/6269_2.png) [@jorge243](https://community.plotly.com/u/jorge243)\
**Post date:** [January 19, 2024, 10:27pm UTC](https://community.plotly.com/t/how-to-get-current-active-shape/42235/7 "2024-01-19T22:27:16Z")

</div>

Just did 🙂 [[Feature Request] Get current active / clicked shape from plotly figure · Issue #2727 · plotly/dash · GitHub](https://github.com/plotly/dash/issues/2727)
