Dark mode refreshes the page but doesn't change the mode

I have an app in which the dark mode is not triggered. It only refreshes the page. Here is a minimal example code.

from panel.template import FastListTemplate
from panel.widgets import StaticText

def main() -> None:
    template: FastListTemplate = FastListTemplate(
        title='Minimal example',
        main=StaticText(
            value='Dark mode seems to only refresh the page.' 
            ' It does not change the mode.'
        )
    )
    template.show()

if __name__ == '__main__':
    main()
1 Like

It works if you serve the app with panel serve ...

from panel.template import FastListTemplate
from panel.widgets import StaticText

def main() -> None:
    return FastListTemplate(
        title='Minimal example',
        main=StaticText(
            value='Dark mode seems to only refresh the page.' 
            ' It does not change the mode.'
        )
    )

if __name__ == '__main__':
    main().show()
elif __name__.startswith("bokeh"):
    main().servable()

Using .show() with main() gives AttributeError: 'NoneType' object has no attribute 'show'. What is the .startswith('bokeh') for? Printing __name__ gives __main__ so the elif condition seems to be useless.

I tried panel serve file.py from command line but I got panel is not recognised. After some searching I came up with

def main() :
    template: FastListTemplate = FastListTemplate(
        title='Minimal example',
        main=StaticText(
            value='Dark mode seems to refresh the page.' 
            ' It does not change the mode.'
        )
    )
    template.servable()
    serve(template)


if __name__ == '__main__':
    main()

which launches the app but the problem remains.

In retrospect I seem to have missed the reformulation of main so that it would return the template. That way I’m able to use main().servable() but it does not solve the problem: mode switch only refreshes the page. It doesn’t change the theme.