There was a problem implementing Notification using dash_martine_components

You are using dash_mantine_components

The problem is that the callback should be executed as much as I want to list.
Notification occurs only once per click on .

What I want is for notifications to occur at the same time as the number of example_list in the code.
(Notification expression as many as the number of example_list when clicking the button, so that the contents of the example_list can be seen in Notification)

I don’t know how to loopback, so I can’t implement it.

Please give me a good opinion

> import dash_mantine_components as dmc
> from dash import Dash, Output, Input, html, callback_context as ctx, no_update, callback
> 
> app = Dash(__name__)
> 
> def update_Noti(intv):
>     if not ctx.triggered:
>         return no_update
>     else:
>         return dmc.Notification(
>             id="notify {}".format(intv),
>             title="title {}".format(intv),
>             message=" message",
>             action="show",
>             autoClose=False,
>             color="red"
>         )
> 
> app.layout = html.Div(
>     [
>         dmc.MantineProvider(
>             dmc.NotificationsProvider([
>                 html.Div(id="caveat-container"),
>             ],
>             limit = 100,
>             position  = "bottom-right"
>             )
>         ),
>         dmc.Group(
>             children=[
>                 dmc.Button(
>                     "Better way",
>                     id="better-notification",
>                 ),
> 
>             ],
>         ),
>     ],
> )
> 
> example_list = ["A", "B", "C", "D", "E"]
> 
> @callback(
>     Output("caveat-container", "children"),
>     [Input("better-notification", "n_clicks")],
> )
> 
> def notify(click):
>     if not ctx.triggered:
>         return no_update
>     else:
>         return update_Noti(click)
> 
> 
> if __name__ == '__main__':
>     app.run_server()

Is this the right way to do it?

> 
> example_list = ["A", "B", "C", "D", "E"]
> 
> for s in example_list :
>     @callback(
>         Output("caveat-container", "children"),
>         [Input("better-notification", "n_clicks")],
>     )
> 
>     def notify(click):
>         if not ctx.triggered:
>             return no_update
>         else:
>             return update_Noti(click)
> 

Hello @ShinDongGeun,

Right now, you are overwriting the div with the new child.

If you want to stack, you need to grab the state of the children of caveat-container. And then add your last child to the end through an append statement.

2 Likes