Skip to content

Feature request: delayed validation #643

Closed

Description

@jquigley3

Validation is awesome, but if all the components are not defined upfront it must be disabled (eg when creating multi-page / multi-file apps).

It is possible to monkey-patch delayed validation. An example is below, but since the introduction of multi-output it is probably not correct. I find this extremely useful, as I always get the @app.callback strings wrong, and even though immediate validation is best, this is much better than nothing.

Perhaps this could be added as a feature! (I of course leave the decision to accept/reject this proposal in your capable hands!)

import dash

_old_validate = dash.Dash._validate_callback
_list = []


def new_validate(self, output, inputs, state):
    _list.append(tuple((output, inputs, state)))

dash.Dash._validate_callback = new_validate


def validate_callbacks(app):
    from dash._utils import create_callback_id as _create_callback_id
    old_map = app.callback_map
    app.callback_map = {} # Monkey patch to trick Dash from raising DuplicateCallbackOutput
    for output, inputs, state in _list:
        _old_validate(app, output, inputs, state)
        callback_id = _create_callback_id
    app.callback_map = old_map

app = dash.Dash(__name__)

# After defining all the callbacks ...

validate_callbacks(app)
app.run_server(**CONFIG)

Activity

  1. ned2 commented on Mar 11, 2019

    @ned2
    Contributor

    I very much agree, and in fact, have just submitted a proposed PR for doing this: #644.

    I ended up taking the same basic approach as yours, but with some extra logic for detecting duplicated Outputs in callbacks (including handling multi-output callbacks). Feedback welcome!

  2. alexcjohnson commented on Mar 12, 2019

    @alexcjohnson
    Collaborator

    Combining this with #519

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions