-
Notifications
You must be signed in to change notification settings - Fork 39
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
How to specify input vs state #5
Comments
Thanks for the ideas. Let me think on them some more. |
I kind of like the idea of supporting a dx.callback(
inputs=...
triggers=[html.Button().props["nclicks"], Input(...)]
) The downside is that you can't control where the trigger element is positioned in the layout this way. We could also add dx.callback(
inputs=[dx.arg(...), dx.arg(...), dx.arg(..., kind="trigger")]
) This doesn't feel too magical to me. Downside is that there wouldn't be a way to use an external But if both were supported, then I think you'd have full flexibility. dx.callback(
inputs=[dx.arg(...), dx.arg(..., kind="trigger"), dx.arg(...)],
triggers=[Input(...)]
) Neither of these changes would require any changes to Dash. |
With the incompatibilities discussed in #6 (comment), I am wondering if it would be better to not reuse the Like you suggested, we could use
All positional arguments and the contents of |
How about this.
|
I like it! Just two questions:
|
Either way, I think we would still want the trigger prop names would still show up in callback context when they aren't passed to the callback function. |
In plotly/dash#1054 I was thinking |
Ok, I see. Yeah, converting a triggered prop to a boolean would be interesting. Wonder if it would make sense for there to be a virtual property for components named button2 = html.Button(...)
@dx.callback(app,
args=dict(
button1=dx.arg(html.Button(), props=("triggered", "n_clicks"))
button2=(Input("button2", "triggered"), Input("button2", "n_clicks"))
)
)
def callback(button1, button2):
button1_triggered, button1_nclicks = button1
button2_triggered, button2_nclicks = button2
... The rule would be that you can only use "triggered" in a tuple/dict grouping that includes at least one real component property. The triggered value would be true if there was a change to any other property in the grouping, and false otherwise. Also, it would only make sense for If there's only one other prop in the grouping, then you know exactly what component/prop triggered the update. But if there is more than one there would still be ambiguity that you'd need to sort out with FWIW, this would be compatible with the proposed Dash Express model, so it could be added after the MVP. Doesn't really address the specifying state vs. input dimension though. |
Right now the docs use
dx.arg
for all inputs/state, defaulting to input but adaptable withkind="state"
. To create an update button you need to addkind="state"
to all the existing inputs and add another like:n_clicks=dx.arg(html.Button("Update").props["n_clicks"])
(I've omitted the impliedkind="input"
)(Related point: this is inside the
inputs=dict(...)
- that might be a little funny since it includes bothinput
andstate
items, would it be better to call thisargs
?)The other options that have been floated previously are
dx.input
/dx.state
- this is slightly more concise but not in the fully-immediate case (which we expect will be the most common case) and requires users to learn about the input/state distinction up front. So overall I probably agree about usingdx.arg
instead.manual=True
that turns all the arguments intoState
and creates a new button that isn't an argument to the function but is the only triggeringInput
. For the specific case of delaying all the inputs this is really nice as it's very concise (no need to change every arg) and doesn't require adding an arg to your function that you aren't going to use. But it's very restricted, as you can't mix and match state and input, you can't control what the button looks like.So
kind="input"|"state"
does seem like the simplest way to get the flexibility we need. But can we make it easier to change between immediate and on-submit modes? If we implementTrigger
inputs in base Dash plotly/dash#1054, maybe we could make adx.trigger("Update")
that creates a button with the given text, and when you add that to your args list it flips the defaultkind
for other args from"input"
to"state"
(so underneath, the default would be"auto"
or something).We could also give the base
Trigger
ahidden=True
option to omit it from the function args, and perhaps let that be the default if your definition only has a singledx.trigger
but turn it off if there are multiple triggers. Or perhaps name your trigger something like_
in the inputs dict and it'll be omitted from the function args?Too magical? Just trying to find more concise syntax for the common cases.
The text was updated successfully, but these errors were encountered: