-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Tidy] Convert built-in actions to pydantic models #1054
base: main
Are you sure you want to change the base?
Conversation
* Convert all built in actions to new system * Make legacy custom actions still work * Legacy built in actions don't work
for more information, see https://pre-commit.ci
# Will need some way to add new components on the fly for other actions though. | ||
# e.g. for key-value pairs on screen | ||
# This could be built into e.g. KeyValuePairs model. | ||
# Petar qn: what other actions would require new components on page? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other actions requiring the insertion of dash_components could be:
drill_through_action
– if we choose to implement it using dcc.Store instead of relying on Dash routing callback inputs.navigate_to_page("page-2")
– if we opt to use dcc.Location for navigation.
Also, since dash_components are "magically" hidden, we should clarify in the documentation how this argument is used, where these components live in the HTML DOM, and why they are hidden.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My idea here is that we have some components that are available for all actions to use as output with some reserved names, e.g. maybe prefixed with vizro_
:
- definitely useful:
vizro_download
, adcc.Download
component - definitely useful:
vizro_location
, adcc.Location
component (same as the Dash pages one but public) - possibly useful:
vizro_store
: adcc.Store
Then you'd be able to write an action with output=["vizro_download"]
for example to use this. So individual actions wouldn't need to ever create new components, just use existing built in ones.
However, there are some assumptions here we should discuss since I'm not sure whether they hold...
- all these components are hidden and globally available on all pages
- it is ok for there to only be one of each component. e.g. we would need to change the current implementation of
export_data
to zip the files into one file and then send that to the singlevizro_download
object rather than dynamically creating ndcc.Download
components like it does now. Would this work ok withdcc.Store
?
If we're not 100% sure but think this scheme will probably work then I'd like to try and do it because it would help us remove the whole dash_components
thing which is only necessary for a couple of actions.
wdyt?
Description
Built in actions
User API:
Before:
actions=[vm.Action(export_data(...))]
After:
actions=[export_data(...)]
The old version still works for backwards compatibility but will go in 0.2.0.
export_data
will stay in 0.2.0 butfilter_interaction
will not.What's changed?
_callback_mapping
is completely gone. Instead these are done next to the function definition in theexport_data
etc. classaction.function._function.__name__ != "_filter"
comparisons or_parameter.__wrapped__
things; instead we can doisinstance(action, _filter)
Custom actions
User API:
Before:
actions=[vm.Action(function=my_custom_action(), inputs=["dropdown_id.value"], outputs=["card.children"])]
After:
actions=[vm.Action(function=my_custom_action("dropdown_id.value"), outputs=["card.children"])]
Before: define action with
@capture("action")
and a function definitionAfter: same still works but there's also a new possibility to do
class my_custom_action(AbstractAction)
for advanced users. These are slightly more powerful than the function variety and can be used as if they were built in actions, likeactions=[my_custom_action(...)]
without needing thevm.Action
wrapper.The old version still works for backwards compatibility but will go in 0.2.0. In 0.2.0 passing static arguments to a custom action is only possible through the class definition approach (though if we really need to in future we could enable it in the function approach too).
What's changed?
controls
directly in their actions to use built in Dash statesinputs
which is way clearerIn future:
trigger
to get the state of the trigger that can be easily consumed in the action without having to explicitly give the component an idactions=[my_custom_action("dropdown_id.value") >> ["card.children"]]
which is equivalent toactions=[vm.Action(function=my_custom_action("dropdown_id.value"), outputs=["card.children"])]
<component>.<property>
in favour of just doing<component>
and using the relevant model's default property. So you'd just docard
rather thancard.children
Notice
I acknowledge and agree that, by checking this box and clicking "Submit Pull Request":