Path: blob/main/examples/reference/global/Notifications.ipynb
3240 views
The NotificationsArea component is a global component which allows users to display so called "toasts" that can provide information to a user. Notifications can be enabled by setting notifications=True via the pn.extension or by setting pn.config.notifications = True directly.
Parameters:
For details on other options for customizing the component see the layout and styling how-to guides.
NotificationArea
Parameters:
position(str): The position of the notifications area.
Methods:
.info(): Issues an info message.error(): Issues an error message.success(): Issues an success message.warning(): Issues an warning message
Notification
Parameters:
duration(int): The duration to display the notification for (if set to zero the notification will be displayed until it has been destroyed or dismissed).type(str): Whether the widget is editable
Methods:
.destroy(): Destroys the notification
By default notifications last for the specified duration specified in milliseconds and defaulting to 3 seconds:
Setting a duration of zero will cause the notification to stay in place until it is either manually dismissed in the UI or destroyed programmatically:
We can destroy it programmatically using the destroy method:
Clear all
To clear out all current notifications we can call the clear method:
Custom types
We are not limited by the four main types of notifications, by using the .send method we can provide a custom background and icon:
Position
The position of the notification area can be controlled by setting the parameter on the state.notifications object, e.g.:
If you are viewing this page in a live notebook you will be able to change the position dynamically:
Demo
To try notifications out yourself the NotificationArea components provide a convenient .demo() method. Note that to set a custom color you have to select the 'custom' type: