Skip to content
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

Make codebase compatible with Dash 2.0 release #354

Closed
GibbsConsulting opened this issue Sep 14, 2021 · 8 comments
Closed

Make codebase compatible with Dash 2.0 release #354

GibbsConsulting opened this issue Sep 14, 2021 · 8 comments
Labels
enhancement New feature or request

Comments

@GibbsConsulting
Copy link
Owner

As well as #351, there is also a need to make django-plotly-dash work with the recent v2.x release(s) of Dash.
One issue has already been reported as #353

@IDepla
Copy link

IDepla commented Oct 26, 2021

I think the problem is with the dash package,
It is bypassing the kwargs so you lose the context that you injected

yourenvironment/dash/_callback.py

//line 142
def add_context(*args, **kwargs):
            output_spec = kwargs.pop("outputs_list")
            _validate.validate_output_spec(insert_output, output_spec, Output)

            func_args, func_kwargs = _validate.validate_and_group_input_args(
                args, inputs_state_indices
            )

            # don't touch the comment on the next line - used by debugger
            output_value = func(*func_args, **func_kwargs)  # %% callback invoked %%

I tried (python3.6) adding

def add_context(*args, **kwargs):
            output_spec = kwargs.pop("outputs_list")
            _validate.validate_output_spec(insert_output, output_spec, Output)

            func_args, func_kwargs = _validate.validate_and_group_input_args(
                args, inputs_state_indices
            )
           mergedic={**func_kwargs, **kwargs}
            # don't touch the comment on the next line - used by debugger
            output_value = func(*func_args, **mergedic)  # %% callback invoked %%

and helps my problem (no user in kwargs).

@GibbsConsulting
Copy link
Owner Author

@IDepla neat fix, thanks. Will see if we can somehow override this function in Dash

@limsammy
Copy link

limsammy commented Nov 17, 2021

@GibbsConsulting @IDepla Hey guys, running into this issue currently.

What is your advice on the best way to implement this fix? I am currently going to simply fork dash, add the fix, and use that for the project until there is an official patch for overriding the dash func in django-plotly-dash, and we can revert back to the official Dash package...

I'm not sure how viable this is, or if I can simply override it myself within the django app without having to touch either dash or django-plotly-dash.

How did you implement this fix? @IDepla I know it is a very ill advised practice to edit anything installed directly under ./myenv/site_packages/, so I am leaning towards forking, adding your fix, and installing with pip install -e git+https://github.com/myorg/dash-fork.git

Any thoughts on this strategy?

EDIT: forking and installing from my github repo does not work, as it does not install modules in a comptabile way, eg. dash_core_components (from dash import dcc is simply an empty function). When I then try to install dash_core_components, it overwrites my fork.

@limsammy
Copy link

Any update on this?

@GibbsConsulting
Copy link
Owner Author

@limsammy one alternative could be to monkey patch that function at runtime - in other words, import the module it is in and set the function equal to the new desired one. You will have to ensure that you do this patching prior to executing any callback.

@IDepla
Copy link

IDepla commented Dec 23, 2021

@limsammy it was meant to be temporary until dash fixes the problem.

I was wondering (but I didn't try), a way to operationalize @GibbsConsulting's comment could be to hijack directly the module cache (https://docs.python.org/3/reference/import.html) since the load of the Django settings. Either way, the dash app is imported after the settings, so you override the cache reference before is called by any other module.

If the fix has to live for longer than expected, a better way would be to just add the variables that you need (and are validated) instead of copying all the **kwargs.

@KuechlerO
Copy link

Another new feature that came in with Dash 2.0 is the "flexible callback".
However, this fails currently when using django-plotly-dash.

Take a look here:
Flexible callbacks failing validation

pieeri added a commit to noosenergy/dash-material-components that referenced this issue Feb 4, 2022
Current incompatibility with jupyter-dash & django-plotly-dash
plotly/jupyter-dash#75
GibbsConsulting/django-plotly-dash#354
@GibbsConsulting
Copy link
Owner Author

v2.0.0 is now out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants