You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+6-32Lines changed: 6 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,60 +25,34 @@ Let's consider a simple example where we want to update the text of a component
25
25
**Using Dash's `clientside_callback`**
26
26
27
27
```python
28
-
import dash
29
-
from dash import html
30
-
from dash.dependencies import Input, Output
28
+
from dash import clientside_callback
31
29
32
-
app = dash.Dash(__name__)
33
-
34
-
app.layout = html.Div([
35
-
html.Input(id="input", type="text"),
36
-
html.Div(id="output")
37
-
])
38
-
39
-
app.clientside_callback(
30
+
clientside_callback(
40
31
"""
41
32
function(value) {
42
33
return 'You entered: ' + value;
43
34
}
44
35
""",
45
36
Output("output", "children"),
46
-
Input("input", "value"),
47
-
37
+
Input("input", "value")
48
38
)
49
-
50
-
if__name__=="__main__":
51
-
app.run_server(debug=True)
52
39
```
53
40
54
41
**Using `better-dash-callback`**
55
42
56
43
```python
57
-
import dash
58
-
from dash import html
59
-
from better_dash_callback import callback
60
-
61
-
app = dash.Dash(__name__)
62
-
63
-
app.layout = html.Div([
64
-
html.Input(id="input", type="text"),
65
-
html.Div(id="output")
66
-
])
44
+
from better-dash-callback import callback
67
45
68
46
@callback(
69
47
Output("output", "children"),
70
48
Input("input", "value"),
71
-
clientside=True,
72
-
prevent_initial_call=True
49
+
clientside=True
73
50
)
74
51
defupdate_output(value):
75
52
returnf"You entered: {value}"
76
-
77
-
if__name__=="__main__":
78
-
app.run_server(debug=True)
79
53
```
80
54
81
-
As you can see, the `better-dash-callback` example is more elegant and easier to read. You can write your callback function using Python syntax, without having to worry about inline JavaScript code.
55
+
As you can see, the `better-dash-callback` example is more elegant and easier to read. You can write your callback function using Python syntax, without having to worry about inline JavaScript code, and the code you write also includes all the python syntax highlighting rather than being javascript code inside of a python string.
82
56
83
57
The `callback` function takes the following additional arguments:
0 commit comments