Skip to content

[Feature Request] allow for callbacks without Inputs #3411

@ghaarsma

Description

@ghaarsma

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.

Image

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3backlogfeaturesomething new

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions