Skip to content

Commit df468db

Browse files
update after review
1 parent 01a6958 commit df468db

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

docs/components_page/components/input.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ When using `Input` with `type="color"`, the user may specify a color, either by
9898

9999
Note that the color picker presentation may vary substantially from one browser and/or platform to another.
100100

101+
As you drag the selector around the color picker, notice that the text color is smoothly updated. While this is a nice feature, it may cause a performance issue in your app, because the callback fires continuously.
102+
103+
This is a great use-case for a [Dash clientside callback](https://dash.plotly.com/clientside-callbacks). This example uses a clientside callback so the callback runs directly in the browser instead of making requests to the Dash server. For your reference, the regular Dash callback is shown as a comment.
104+
101105
{{example:components/input/colorpicker.py:colorpicker}}
102106

103107

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import dash_bootstrap_components as dbc
12
import dash_html_components as html
23
from dash.dependencies import Input, Output
3-
import dash_bootstrap_components as dbc
44

55
colorpicker = dbc.FormGroup(
66
[
7-
dbc.Label("Choose the text color:", id="label"),
7+
dbc.Label(["Select a ", html.Span("color", id="color")]),
88
dbc.Input(
99
type="color",
1010
id="colorpicker",
@@ -14,9 +14,18 @@
1414
]
1515
)
1616

17-
18-
@app.callback(
19-
Output("label", "style"), Input("colorpicker", "value"),
17+
app.clientside_callback(
18+
"""
19+
function(color) {
20+
return {"color": color}
21+
}
22+
""",
23+
Output("color", "style"),
24+
Input("colorpicker", "value"),
2025
)
21-
def update_text(color):
22-
return {"color": color}
26+
27+
28+
# Regular Dash callback
29+
# @app.callback(Output("color", "style"), Input("colorpicker", "value"))
30+
# def update_text(color):
31+
# return {"color": color}

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ exclude =
1515
docs/components_page/components/input/simple.py,
1616
docs/components_page/components/input/radio_check_standalone.py,
1717
docs/components_page/components/input/radio_check.py,
18+
docs/components_page/components/input/colorpicker.py,
1819
docs/components_page/components/input_group/button.py,
1920
docs/components_page/components/input_group/dropdown.py,
2021
docs/components_page/components/list_group/links.py,

0 commit comments

Comments
 (0)