-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
I would like to request a feature enhancement to allow for callbacks to not have an input, but rely on having a State and an initial call / load to perform useful work.
Currently Dash does not allow for callbacks without inputs. I think this makes sense in most cases and the check/limit will aid most novice Dash developers.
My counter example is where we have a callback that does have a State (but no real Inputs), but depending on the value of the State, during the initial load will fetch some values from a external database and update Options and Value of a dcc.Dropdown
At the moment we solve this be adding a fake-input in the following way:
layout = html.Div(
[
dcc.Dropdown(id=f"my-dropdown"),
dcc.Interval(id="fake_input", n_intervals=0, max_intervals=0, interval=1),
]
)
@callback(
Output("my-dropdown", "options"),
Output("my-dropdown", "value"),
Input("fake_input", "n_intervals"),
)
But this makes the callback map much messier and larger then it needs to be, specially if you have multiple drop downs.
I have tried to comment out the 3 JS lines that does the check in dash_renderer.dev.js
and everything seems to work just fine as intended for my particular use case.

So: keep the check mostly as is, but allow for callbacks that lack Inputs, but have States and have prevent_initial_call
as False. Optionally, If we think it's to dangerous to allow no-input-callbacks in the general sense, we could add a kwarg to the callback to bypass the check. Something like: allow_no_inputs = True
for individual edge cases like my counter example.