Skip to content

Commit 70f577d

Browse files
committed
reduce boilerplate in basic_hello_structure_interactive.py using prevent_initial_callbacks
1 parent 30dab9f commit 70f577d

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

crystal_toolkit/apps/examples/basic_hello_structure_interactive.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44

55
# standard Dash imports for callbacks (interactivity)
66
from dash.dependencies import Input, Output
7-
from dash.exceptions import PreventUpdate
87
from pymatgen.core.lattice import Lattice
98
from pymatgen.core.structure import Structure
109

1110
import crystal_toolkit.components as ctc
1211

13-
app = dash.Dash()
12+
app = dash.Dash(
13+
prevent_initial_callbacks=True, # don't run callbacks on page load
14+
)
1415

1516
# now we give a list of structures to pick from
1617
structures = [
@@ -30,16 +31,13 @@
3031

3132
ctc.register_crystal_toolkit(app=app, layout=my_layout)
3233

34+
3335
# for the interactivity, we use a standard Dash callback
3436
@app.callback(
3537
Output(structure_component.id(), "data"),
3638
[Input("change_structure_button", "n_clicks")],
3739
)
3840
def update_structure(n_clicks):
39-
# on load, n_clicks will be None, and no update is required
40-
# after clicking on the button, n_clicks will be an int and incremented
41-
if not n_clicks:
42-
raise PreventUpdate
4341
return structures[n_clicks % 2]
4442

4543

0 commit comments

Comments
 (0)