Notifications with templates

Is it possible to get the newly released notifications feature to work with a template? Clicking btn in the following code seems to work when I render the button in a notebook, but not when it’s rendered in the template…

import panel as pn

pn.extension(notifications=True)

def notify(event):
    pn.state.notifications.info('this is a notification')
    
btn = pn.widgets.Button(name='Notify')
btn.on_click(notify)

template = pn.template.FastGridTemplate(sidebar=[btn])
template.show()
1 Like

At least when served with panel serve from the commandline this works fine. I think when you run .show it gets confused about the pn.state.notification instance it’s meant to use however and it doesn’t work. Definitely worth filing an issue about this on the Panel issue tracker.

2 Likes

Just to make the working .servable code clear here is the working version

import panel as pn

pn.extension(notifications=True)

def notify(event):
    pn.state.notifications.info('this is a notification')
    
btn = pn.widgets.Button(name='Notify')
btn.on_click(notify)

template = pn.template.FastGridTemplate(sidebar=[btn])
template.servable()
1 Like

I made a bug report here Notifications do not work with .show() · Issue #3445 · holoviz/panel (github.com)

1 Like

I had wondered if it was a .servable() vs .show() issue. Thanks for filing the bug report @Marc!

1 Like