Right now the docs use dx.arg for all inputs/state, defaulting to input but adaptable with kind="state". To create an update button you need to add kind="state" to all the existing inputs and add another like:
n_clicks=dx.arg(html.Button("Update").props["n_clicks"]) (I've omitted the implied kind="input")
(Related point: this is inside the inputs=dict(...) - that might be a little funny since it includes both input and state items, would it be better to call this args?)
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 using dx.arg instead.
- a separate argument
manual=True that turns all the arguments into State and creates a new button that isn't an argument to the function but is the only triggering Input. 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 implement Trigger inputs in base Dash plotly/dash#1054, maybe we could make a dx.trigger("Update") that creates a button with the given text, and when you add that to your args list it flips the default kind for other args from "input" to "state" (so underneath, the default would be "auto" or something).
We could also give the base Trigger a hidden=True option to omit it from the function args, and perhaps let that be the default if your definition only has a single dx.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.
Right now the docs use
dx.argfor 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 bothinputandstateitems, 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.arginstead.manual=Truethat turns all the arguments intoStateand 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 implementTriggerinputs 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 defaultkindfor other args from"input"to"state"(so underneath, the default would be"auto"or something).We could also give the base
Triggerahidden=Trueoption to omit it from the function args, and perhaps let that be the default if your definition only has a singledx.triggerbut 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.