Returning a container to the dashboard with colored text

@majudd so we are in the same boat.

Could you explain a bit more, what you are trying to do? How does your code look like? With the information you provided ist is difficult to help you.

It would be very helpful if you created a MRE

EDIT: by any chance you are looking for something like this?

from dash import Dash, Input, Output, html, ctx

app = Dash(__name__)

app.layout = html.Div(
    [
        html.Div(
            id='dump',
            children=['color string'],
            style={
                'font-size': 60,
                'text-align': 'left'
            }
        ),
        html.Button(
            'red',
            id='red'
        ),
        html.Button(
            'yellow',
            id='yellow'
        )
    ]
)


@app.callback(
    Output('dump', 'style'),
    Input('red', 'n_clicks'),
    Input('yellow', 'n_clicks'),
    prevent_initial_call=True
)
def start_interval(red, yellow):
    # since the two buttons have the id "red" and "yellow" 
    # the triggered id will be just ste color string
    
    color = ctx.triggered_id
    return {
            'color': color,
            'font-size': 60,
            'text-align': 'left'
    }


if __name__ == "__main__":
    app.run(debug=True)

creates:
colors

1 Like