How to remove sidebar and update the webpage after template is served

Hi @Jason

Welcome to the community :+1:

The template .sidebar is not dynamic. I.e. you cannot remove elements after the app has loaded. It will be possible one day.

Instead you can use code like the below

import panel as pn

pn.extension()

button = pn.widgets.Button(name="Remove sidebar", button_type="primary")
button.js_on_click(
    code="""
document.getElementById('sidebar-button').style.display = 'none';
document.getElementById('sidebar').style.display = 'none';
"""
)

main = pn.pane.Markdown("# Click button to remove sidebar")


@pn.depends(button, watch=True)
def _update_main(_):
    main.object = "# Sidebar removed"


pn.template.FastListTemplate(sidebar=[button], main=[main]).servable()

Try it on PY.CAFE

2 Likes