But even if the button was deleted outright, the box would still remain because the core Factorio library responsible for it doesn't handle this case in any way. And Factory Planner interferes with the library to remove the box, which I think is wrong.
Since the core Factorio library didn't fix that for years and the fix in Factory Planner just works fine for years, I would highly propose to just do the same. Leaving a empty box is really annoying and it's easy to fix.
Out of Factory Planner util/gui.lua:
local function check_empty_flow(player)
local button_flow = mod_gui.get_button_flow(player)
-- parent.parent is to check that I'm not deleting a top level element. Now, I have no idea how that
-- could ever be a top level element, but oh well, can't know everything now can we?
if #button_flow.children_names == 0 and button_flow.parent.parent then
button_flow.parent.destroy()
end
end