Skip to content

Initial n_clicks for a Button is None instead of 0 inside a callback #177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Akronix opened this issue Dec 12, 2017 · 3 comments
Closed

Comments

@Akronix
Copy link
Contributor

Akronix commented Dec 12, 2017

I have a Button imported from dash_html_components and I'm using it as an Input for a callback. In the very first execution, the initial value of n_clicks is None, but I would expect it to be 0 😕

@chriddyp
Copy link
Member

Yeah, that's definitely confusing. Right now, any unspecified property in a dash component defaults to None (so at least the behaviour is consistent).
You can get around this by explicitly setting the initial property of the component in the layout with e.g.

app.layout = html.Div([
    html.Button(n_clicks=0)
])

@Akronix
Copy link
Contributor Author

Akronix commented Dec 12, 2017

Ok that works.
However, it is specially confusing when you see that the Button react component initial state is 0, whereas that in Dash callback it evaluates to None.

@chriddyp
Copy link
Member

Yeah, perhaps in the future we can use the values in the defaultProps as the initial state. That could be done as part of the push described in #150 (comment)

HammadTheOne pushed a commit to HammadTheOne/dash that referenced this issue May 22, 2021
…age if failed (plotly#177)

* add check that dash was imported and exit with useful message if not

* added test to check sys.exit(1) called when dash not import correctly

* fix wrong module name
AnnMarieW pushed a commit to AnnMarieW/dash that referenced this issue Jan 6, 2022
…age if failed (plotly#177)

* add check that dash was imported and exit with useful message if not

* added test to check sys.exit(1) called when dash not import correctly

* fix wrong module name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants