Removing dynamically added bokeh plot

Hi, I am adding bokeh plot like this:

              const tileScript = document.querySelector("#tileScript");
              tileScript!.setAttribute("data-tile-query", resp.data);
              const script = document.createElement("script");
              script.setAttribute("id", "plotscript");
              script.src = process.env.PUBLIC_URL + "load-plot.js";
              script.async = false;
              document.body.appendChild(script);

This works great.

However when i try to remove the plot again i do like this:

                  onClick={() => {
                    const tileScript = document.querySelector("#tileScript");
                    tileScript!.removeAttribute("data-tile-query");
                    document.getElementById("plotscript")!.remove();
                  }}

I get no errors…but the plot is also not removed :frowning: What am I missing here?