@@ -156,28 +156,32 @@ callback is set. A typical compressed data download callback will look like
156
156
@app.callback(self.plugin_data_output,
157
157
self.plugin_data_requested)
158
158
def _user_download_data(data_requested):
159
- return WebvizPluginABC.plugin_compressed_data(
160
- file_name="webviz-data.zip",
161
- content=[{'filename': 'some_file.txt',
162
- 'content': 'Some download data'}]
163
- ) if data_requested else {}
159
+ return (
160
+ WebvizPluginABC.plugin_compressed_data(
161
+ filename="webviz-data.zip",
162
+ content=[{"filename": "some_file.txt", "content": "Some download data"}],
163
+ )
164
+ if data_requested
165
+ else None
166
+ )
164
167
` ` `
165
168
166
- A typical raw CSV data download will look like :
169
+ A typical CSV data download from e.g. a `pandas.DataFrame` will look like :
167
170
` ` ` python
168
171
@app.callback(self.plugin_data_output,
169
172
self.plugin_data_requested)
170
173
def _user_download_data(data_requested):
171
- if data_requested:
172
- byte_io = io.BytesIO()
173
- byte_io.write(get_data(self.csv_file).to_csv().encode('ascii'))
174
- byte_io.seek(0)
175
- return {
176
- "file_name": "file_name.csv",
177
- "content": base64.b64encode(byte_io.read()).decode("ascii"),
178
- "mime_type": "text/csv"
179
- }
180
- return {}
174
+ return (
175
+ {
176
+ "filename": "some-file.csv",
177
+ "content": base64.b64encode(
178
+ some_pandas_dataframe.to_csv().encode()
179
+ ).decode("ascii"),
180
+ "mime_type": "text/csv",
181
+ }
182
+ if data_requested
183
+ else None
184
+ )
181
185
` ` `
182
186
183
187
By letting the plugin define the callback, the plugin author is able
0 commit comments