How to programmatically set the bootstrap template in the ThemeChangerAIO?

I’m using ThemeChangerAIO for theme changing. I would like to save the user-selected theme in cookies and re-load it when the page loads again, but I don’t know to programmatically set the value in ThemeChangerAIO and have it refresh the layout?

Hi @kiteme

You can set persistence=True in the underlying dbc.RadiioItems component in the ThemeChangerAIO For example:

ThemeChangerAIO(aio_id="theme", radio_props={"persistence": True})

Note that you can pass any valid parameter to any of the underlying components:

  • The change theme button is a dbc.Button. Use the button_props parameter
  • The side nav with the themes is a dbc.Offcanvas. Use the offcanvas_props
  • Themes are selected with a dbc.RadioItems. Access this with the radio_props

For example, if you would also like to change the button, you could add:

ThemeChangerAIO(
    aio_id="theme",
    radio_props={"persistence": True},
    button_props={
        "color": "danger",
        "children": "select theme",
    },
)

Thank you @AnnMarieW!