dmc.Button in loading state without background callbacks?

Hi, I’m using the dash mantine components very frequently lately and I’m loving it.

I’ve noticed that the buttons has a loading param which can very elegantly display a spinner replacing the icon.
How do I activate that loading state throughout the duration of my callback if I do not want to use background callbacks?

Is there any neat tricks I can use?
I’ve checked the dcc.loading documentation as well, but I’m not sure if I can stitch it together with that…

Thanks in advance,

Hey @dansah, interesting question!

Since dash allows duplicate outputs from version 2.9.0, you could do something like that:

import time

import dash
import dash_mantine_components as dmc
from dash import Input, Output, html, dcc
from dash_iconify import DashIconify

app = dash.Dash(

app.layout = html.Div([
        "Connect to Database",

    Output('btn', 'leftIcon', allow_duplicate=True),
    Input('btn', 'n_clicks'),
def update(_):
    return dcc.Loading()

    Output('store', 'data'),
    Output('btn', 'leftIcon'),
    Input('btn', 'leftIcon'),
def update(_):
    return {}, [DashIconify(icon="fluent:database-plug-connected-20-filled")]

if __name__ == "__main__":


mred dupout


Thanks @AIMPED - that is a clever use of the duplicate outputs!

I’ve tweaked your example a bit and are hitting the loading state of the button instead of changing the icon, the effect is the same just plain dmc instead of injecting the dcc.Loading component in there.

Thanks a ton!

1 Like

Added a dedicated section here:

1 Like

FYI you probably want to make the first callback (the one that just changes the loading attribute) a clientside one to ensure that it runs before the other. When I tried on the DMC website the order got reversed and the button got stuck in loading state after having retrieved the ‘results’.

1 Like

yeah, corrected that. Thanks!

1 Like

A post was split to a new topic: dbc.Button in loading state without background callbacks