Quantcast
Channel: 🎛️ Dash - Plotly Community Forum
Viewing all articles
Browse latest Browse all 6271

Toggle a button children

$
0
0

Hello, i am new in plotly and dash.
I wanted to implement a start and stop mechanism by one button.
As first step, I wanted that, o page load the button will show Start and after clicking it will show Stop

import dash
from dash.dependencies import Input, Output
import dash_html_components as html

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

app.layout = html.Div([
    html.Button(children='Start', id='btn1', n_clicks=0)
])

@app.callback(Output('btn1', 'children'),
              Input('btn1', 'children'))
def displayClick(cld):
    changed_id = [p['prop_id'] for p in dash.callback_context.triggered][0]
    if 'btn1' in changed_id:
        if cld=='Start':
            return 'Stop'
        else:
           return 'Start'


if __name__ == '__main__':
    app.run_server(debug=True)

It is not working even the initial ‘Start’ not showing.

Could you help me to understand the problem?

2 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 6271

Latest Images

Trending Articles



Latest Images