Skip to content

Commit c052a5e

Browse files
committed
0.2.0 - update example
Update the `examples/download_file` to match the usage of the new `Downloader` component.
1 parent 75326aa commit c052a5e

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#### :floppy_disk: Change
1515

1616
1. Drop the legacy `components.downloader` module because it has been replaced by `components.PlainDownloader` now.
17+
2. Update the `examples/download_file` to match the usage of the new `Downloader` component.
1718

1819
### 0.1.2 @ 10/13/2024
1920

examples/download_file.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,6 @@ def __init__(self) -> None:
5656
self.service = ServiceData(CacheFile(None))
5757
self.root = os.path.dirname(__file__)
5858

59-
self.downloader = Downloader(
60-
id="download",
61-
to_addr=(
62-
lambda trigger: (trigger[8:] if trigger.startswith("success-") else "")
63-
),
64-
)
65-
6659
def layout(self) -> html.Div:
6760
return html.Div(
6861
(
@@ -79,13 +72,11 @@ def layout(self) -> html.Div:
7972
html.Div((html.P(("Progress:", html.Span(id="prog"))))),
8073
html.Div((html.P("Cache type:"), html.P(id="type"))),
8174
html.Div((html.P("Cache address:"), html.P(id="addr"))),
82-
self.downloader.layout(),
75+
Downloader(id="download"),
8376
),
8477
)
8578

8679
def bind(self, app: dash.Dash):
87-
self.downloader.use_callbacks(app)
88-
8980
@app.callback(
9081
Output("type", "children"),
9182
Output("addr", "children"),
@@ -119,14 +110,14 @@ def click_get_image(
119110
return str(file_path.__class__.__name__), addr
120111

121112
@app.callback(
122-
self.downloader.as_output,
113+
Output("download", "url"),
123114
Input("addr", "children"),
124115
prevent_initial_call=True,
125116
)
126117
def trigger_downloading_event(addr):
127118
if not addr:
128119
return dash.no_update
129-
return "success-{0}".format(addr)
120+
return addr
130121

131122

132123
class WrappedApp:

0 commit comments

Comments
 (0)