fohrloop / dash-uploader

The alternative upload component for python Dash applications.
MIT License
144 stars 30 forks source link

Usable with DjangoDash? #58

Closed amd-pscannell closed 2 years ago

amd-pscannell commented 2 years ago

Curious if this is supposed to work with DjangoDash or if I have some versioning issue, I get the following error trying it out

from django_plotly_dash import DjangoDash
import dash_uploader as du

app = DjangoDash('Scratch')
du.configure_upload(app.caller_module.dash.Dash, 'C:\\tmp')

dash 1.17.0 dash-core-components 1.13.0 dash-resumable-upload 0.0.3 dash-uploader 0.6.0 Django 3.1.7 django-plotly-dash 1.4.2

File "C:\Users\User\AppData\Local\Programs\Python\Python38\lib\site-packages\dash_uploader\configure_upload.py", line 60, in configure_upload settings.requests_pathname_prefix = app.config.get("requests_pathname_prefix", "/") AttributeError: type object 'Dash' has no attribute 'config'

fohrloop commented 2 years ago

Interesting! Never heard of DjangoDash before! Seems that not out of the box. I have to take a closer look at some point:)

fohrloop commented 2 years ago

Hey!

Okay I checked the django-plotly-dash out a bit, and it seems that DjangoDash is a bit more complicated from dash-uploader's perspective than Dash, as it says: Multiple Dash apps can then be embedded into a single web page, persist and share internal state, and also have access to the current user and session variables.

I also read the source code a bit and based on it I would guess that it might not be easy to provide, at least full, support for DjangoDash. I won't say complete no for DjangoDash, but at this point it's not on the priority list at least for me. If someone manages to get dash-uploader to work with DjangoDash, and can convince me all the edge cases of both (Dash & DjangoDash) can be supported at the same time without too much difficulties, I could be open to add the support into dash-uploader. Otherwise it might be wiser to create a django-dash-uploader for DjangoDash.

As for your case, the du.configure_upload() wants an instance of dash.Dash as the first argument. Now, you were giving the class/type directly. I read from the django_plotly_dash/dash_wrapper.py) that in the DjangoDash class there is a as_dash_instance() method which returns a WrappedDash instance, which is a DjangoDash specific subtype of dash.Dash. So, if you're lucky, this could work (no guarantees of any kind, though):

app = DjangoDash('Scratch')
du.configure_upload(app.as_dash_instance(), 'C:\\tmp')
amd-pscannell commented 2 years ago

Thanks for taking a peek np-8 The "app.as_dash_instance()" seems to be broken but good suggestion

I'll let you know if I find a way around this!