For sidebars, it looks like you can programmatically change whether it is shown:
and we have a feature request for this setting on headers!
For the sidebar, you could use setHidden as mentioned below, or you could put something in the hidden field that can be toggled programmatically, such as temporary state (described in more detail here).