Description
Question
Hi team and happy new year :) !
I am trying to enable data downlaod for my dashboard user. The export_data action coupled with a button works fine, but I need to use a file format specific to my industry (in that case it is COMTRADE).
As a result I went on to find the export_data action from the vizro codebase and modify it with the following plan in mind:
1 - Wrap a COMTRADE save method as a pandas save method, to_comtrade
by creating a pandas extension;
2 - Modify the action so that it allows "comtrade" as a file format and add filetered_data.to_comtrade
as a writer;
I thought that would be all, but for some reason that I am not understanding, just the fact of copy/pasting the export_data action to my project and importing it instead of the vizro one does not work. In practice, inspecting the context dict shows that it is empty.
Code/Examples
I have made a tentative implementation in PyCafe. Clicking on the button will first print the ctds
and targets
variables:
ic| ctds: {}
ic| targets: []
and generate the following error:
ERROR:app:Exception on /_app/m5ma8d6totf3yot30yf/_dash-update-component [POST]
Traceback (most recent call last):
File "/lib/python3.12/site-packages/flask/app.py", line 1473, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.12/site-packages/flask/app.py", line 882, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.12/site-packages/flask/app.py", line 880, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.12/site-packages/flask/app.py", line 865, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args) # type: ignore[no-any-return]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.12/site-packages/dash/dash.py", line 1376, in dispatch
ctx.run(
File "/lib/python3.12/site-packages/dash/_callback.py", line 507, in add_context
raise err
File "/lib/python3.12/site-packages/dash/_callback.py", line 496, in add_context
output_value = _invoke_callback(func, *func_args, **func_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.12/site-packages/dash/_callback.py", line 43, in _invoke_callback
return func(*args, **kwargs) # %% callback invoked %%
^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.12/site-packages/vizro/models/_action/_action.py", line 181, in callback_wrapper
return_value = self._action_callback_function(inputs=external, outputs=callback_outputs.get("external"))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.12/site-packages/vizro/models/_action/_action.py", line 110, in _action_callback_function
return_value = self.function(**inputs)
^^^^^^^^^^^^^^^^^^^^^^^
File "/lib/python3.12/site-packages/vizro/models/types.py", line 153, in __call__
return self.__function(**{**self.__bound_arguments, **kwargs})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/pyodide/project-files/export_data_action.py", line 67, in export_data
for target, unfiltered_data in _get_unfiltered_data(ctds["parameters"], targets).items():
~~~~^^^^^^^^^^^^^^
KeyError: 'parameters'
I would really appreciate some help! Thank you :)
Which package?
vizro
Code of Conduct
- I agree to follow the Code of Conduct.