# How to delete! in GLMakie

**URL:** <https://discourse.julialang.org/t/how-to-delete-in-glmakie/92259>\
**Category:** Visualization\
**Tags:** plotting, makie, glmakie\
**Created:** [December 29, 2022, 6:31am UTC](https://discourse.julialang.org/t/how-to-delete-in-glmakie/92259 "2022-12-29T06:31:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dyatunin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dyatunin/32/45450_2.png) [@dyatunin](https://discourse.julialang.org/u/dyatunin)\
**Post date:** [December 29, 2022, 6:31am UTC](https://discourse.julialang.org/t/how-to-delete-in-glmakie/92259/1 "2022-12-29T06:31:58Z")

</div>

I am attempting to create an GUI with GLMakie, where elements can be added and removed interactively. I specifically want to remove groups of several Blocks at a time, but I can’t seem to be able to remove even a single Block. Here is a minimum working example:

```julia
using GLMakie
f = Figure()
b = Button(f[1, 1]; label = "Delete Me!")
delete!(b) # doesn't delete b :(
display(f)

```

The [docs](https://docs.makie.org/v0.19.0/documentation/blocks/index.html#deleting_blocks) seem to indicate that this should work?

I am running the latest version of GLMakie (v0.8.0) on macOS Monetery (v12.5).

---

<div class="post-metadata">

**Author:** ![Hawkes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hawkes/32/22365_2.png) [@Hawkes](https://discourse.julialang.org/u/Hawkes)\
**Post date:** [December 29, 2022, 6:46am UTC](https://discourse.julialang.org/t/how-to-delete-in-glmakie/92259/2 "2022-12-29T06:46:38Z")

</div>

Your code works fine for me (opens an empty figure and if I comment the `delete!` statement, the button is visible). Julia 1.9 release branch + GLMakie 0.8 + macOs Ventura…

---

<div class="post-metadata">

**Author:** ![dyatunin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dyatunin/32/45450_2.png) [@dyatunin](https://discourse.julialang.org/u/dyatunin)\
**Post date:** [December 29, 2022, 6:53am UTC](https://discourse.julialang.org/t/how-to-delete-in-glmakie/92259/3 "2022-12-29T06:53:09Z")

</div>

Hmm, I’m still on 1.8.4. I’m going to try upgrading.

---

<div class="post-metadata">

**Author:** ![dyatunin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dyatunin/32/45450_2.png) [@dyatunin](https://discourse.julialang.org/u/dyatunin)\
**Post date:** [December 29, 2022, 7:02am UTC](https://discourse.julialang.org/t/how-to-delete-in-glmakie/92259/4 "2022-12-29T07:02:46Z")

</div>

Doesn’t seem to work for me on 1.9.0 either. Anything else I should check?

---

<div class="post-metadata">

**Author:** ![Hawkes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hawkes/32/22365_2.png) [@Hawkes](https://discourse.julialang.org/u/Hawkes)\
**Post date:** [December 29, 2022, 7:06am UTC](https://discourse.julialang.org/t/how-to-delete-in-glmakie/92259/5 "2022-12-29T07:06:51Z")

</div>

Should not be necessary (I’m just to hyped for the new native code caching and 1.9 is actually quite stable already for my work)…

I have just switched back to 1.8 (still GLMakie 0.8) and run your code… Still works here!? The only remaining difference is the macOS version (which should not matter). I’m running the M1 version of Julia, not Rosetta.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [December 29, 2022, 7:19am UTC](https://discourse.julialang.org/t/how-to-delete-in-glmakie/92259/6 "2022-12-29T07:19:18Z")

</div>

Deleting blocks doesn’t work reliably currently, I think if it was working before the refactor it didn’t work anymore afterwards. It’s tricky to correctly clean up all observable traces and there hasn’t been a focus on it, yet.

---

<div class="post-metadata">

**Author:** ![dyatunin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dyatunin/32/45450_2.png) [@dyatunin](https://discourse.julialang.org/u/dyatunin)\
**Post date:** [December 30, 2022, 4:33am UTC](https://discourse.julialang.org/t/how-to-delete-in-glmakie/92259/7 "2022-12-30T04:33:15Z")

</div>

After a great deal of tinkering, I have found that the following solution works for me:

```julia
using GLMakie
f = Figure()
b1 = Button(f[1, 1]; label = "Delete Me!")
b2 = Button(f[2, 1]; label = "Don't Delete Me!")
delete!(b1)
empty!(b1.blockscene)
trim!(f.layout)
display(f)

```

(The order of the `delete!` and `empty!` calls does not matter.)

Although `b1` is no longer visible and the rest of `f` is adjusted accordingly, I suspect that there are still traces of `b1` remaining in `f`. Any suggestions for how to easily locate all of them?

---

<div class="post-metadata">

**Author:** ![fatteneder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fatteneder/32/33991_2.png) [@fatteneder](https://discourse.julialang.org/u/fatteneder)\
**Post date:** [December 30, 2022, 10:00am UTC](https://discourse.julialang.org/t/how-to-delete-in-glmakie/92259/8 "2022-12-30T10:00:14Z")

</div>

Here is a hackish solution I crafted a while ago to remove `Blocks`: [Makie workflow to access and change attributes of objects - #5 by fatteneder](https://discourse.julialang.org/t/makie-workflow-to-access-and-change-attributes-of-objects/89058/5)

Not 100% sure if it really cuts all ties. It also uses internals of `GridLayoutBase`, so don’t expect this to run on all versions. I think I developed this on `Makie@v0.18.x`.
