Skip to content

Commit 062b38d

Browse files
improve elegancy of example in docs
Signed-off-by: Richard Barella <ribab127@gmail.com>
1 parent a46ec73 commit 062b38d

File tree

2 files changed

+6
-33
lines changed

2 files changed

+6
-33
lines changed

README.md

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,60 +25,34 @@ Let's consider a simple example where we want to update the text of a component
2525
**Using Dash's `clientside_callback`**
2626

2727
```python
28-
import dash
29-
from dash import html
30-
from dash.dependencies import Input, Output
28+
from dash import clientside_callback
3129

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(
4031
"""
4132
function(value) {
4233
return 'You entered: ' + value;
4334
}
4435
""",
4536
Output("output", "children"),
46-
Input("input", "value"),
47-
37+
Input("input", "value")
4838
)
49-
50-
if __name__ == "__main__":
51-
app.run_server(debug=True)
5239
```
5340

5441
**Using `better-dash-callback`**
5542

5643
```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
6745

6846
@callback(
6947
Output("output", "children"),
7048
Input("input", "value"),
71-
clientside=True,
72-
prevent_initial_call=True
49+
clientside=True
7350
)
7451
def update_output(value):
7552
return f"You entered: {value}"
76-
77-
if __name__ == "__main__":
78-
app.run_server(debug=True)
7953
```
8054

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.
8256

8357
The `callback` function takes the following additional arguments:
8458

examples/example.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
@callback(
1313
Output("output", "children"),
1414
Input("input", "value"),
15-
prevent_initial_call=True,
1615
clientside=True
1716
)
1817
def update_output(value):

0 commit comments

Comments
 (0)