Py.Cafe

Letshadow/

dash-mantine-button-trigger

Interactive Button Trigger System

DocsPricing
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from dash import Dash, Input, Output,State, callback, dcc, html,ALL,ctx
import dash_mantine_components as dmc  
app = Dash(__name__)  
 
app.layout = dmc.MantineProvider([  
    # Botones tipo A (triggers)  
    dmc.Button("Botón A 11", id={'type': 'A', 'index': "11"}),  
    dmc.Button("Botón A 23", id={'type': 'A', 'index': "23"}),
    dmc.Button("Botón RESET", id={'type': 'A', 'index': "1111"}),  
    dmc.Divider(color="red"),
     
    # Botones tipo B (targets)  
    dmc.Button("Botón B 111", id={'type': 'B', 'index': "111"},disabled=False,color="red"),  
    dmc.Button("Botón B 211", id={'type': 'B', 'index': "211"},disabled=True),  
    dmc.Button("Botón B 311", id={'type': 'B', 'index': "311"},disabled=True),  
    dmc.Button("Botón B 123", id={'type': 'B', 'index': "123"},disabled=True),  
    dmc.Button("Botón B 523", id={'type': 'B', 'index': "523"},disabled=True),  
])
 
 
@callback(
    Output("markdown", "style"),
    Input("dropdown", "value"),
)
def update_markdown_style(color):
    return {"color": color}
 
 
 
# from dash import Dash, html  
 
 
 
 
@callback(
    Output({'type': 'B', 'index': ALL}, 'disabled'),  
    Input({'type': 'A', 'index': ALL}, 'n_clicks'),
    State({'type': 'B', 'index': ALL}, 'disabled'),  
    prevent_initial_call=True  
)  
def disable_buttons(n_clicks_list,n_disble):  
    if not any(n_clicks_list):  
        return [False] * len(ctx.outputs_list)  
     
    # Obtener el ID del botón que fue clickeado  
    trigger_index = list(ctx.triggered_id['index'])  # [y, z]  desempaquetar
     
    # Lista para almacenar el estado disabled de cada botón tipo B  
    disabled_states = []
 
    for n in range(len(ctx.outputs_list)):  
        button_index = list(ctx.outputs_list[n]['id']['index'])  # [x, y, z]  desempaquetar
        # Verificar si el index del botón contiene los valores [y, z] al final  
        if len(button_index) >= len(trigger_index):              
            # Comprobar si los últimos elementos coinciden  
            if button_index[-len(trigger_index):] == trigger_index: #Comaparar y-y z-z
                disabled_states.append(True)  # Deshabilitar  
            else:
               
                disabled_states.append(n_disble[n])  # Mantener actual  
        else:  
            disabled_states.append(False)
 
    return disabled_states