Plotly in django without django-plotly-dash

Hello.

I would like to know if there is a way to use plotly Dash in Django 3.2 without django-plotly-dash.

I am absolutely frustrated with the issue of static files (css, js, etc). I have spent countless hours trying to get one of the demos available on the internet to work without success.

The example at GitHub - cryptopotluck/plotly-dash-django-udemy: The tutorial I made on connecting django, dash & plotly together shows a screen saying that 127.0.0.1 refused to connect, I already have X_FRAME_OPTIONS = ā€˜SAMEORIGINā€™ in the settings file.

With another demo I get the message
ā€œGET /static/dpd/assets/appPanel/app/dash-logo.png HTTP/1.1ā€ 404 1873

In my project there is no dpd folder
nowhere and I donā€™t know why it looks for it and tried to put the asset folder in various parts of the static route without any existence.

ā€œGET /django_plotly_dash/app/viewport/assets/dash-logo.png HTTP/1.1ā€ 302 0

There is also no app folder or viewport in my project. I really donā€™t know how to understand where plotly looks for statics.

On the other hand, it seems to me that django_plotly_dash is not being maintained, I wrote to GibbsConsulting
asking if they have plans to support plotly 2.2.0 and got no answer.

Maybe someone has a demo django 3.2 project with plotly working fine with static files (css and js) can share it with me.

I am really stuck.

For Dash, you need to put assets in the same folder as your app.
I worked on Django with plotly graphs, but having to switch from python to html to css to js made the work impossible.
Then I switched to django-plotly-dash, but I had to deal with all the naming/folder conventions of Django, and I had to rely on GibbsConsulting for maintenance (371 stars is kind of meh for my work, compared to the 16k stars of Dash), and couldnā€™t use dbc, so I switched to Flask (58k stars).

Stars on Github have become my standard of library quality.

I have a backend in django, which is a simple api with no front. My front is, as I said, in Flask, which is more reliable than Django for Dash.

Anyway, in my older version of django + plotly without dash, the css folder, as well as the js, img, etc are in /home/static/home/, where home is a default app where I gathered all the utilities. This is working fine if you know how to import plotly graphs (which is based on d3.js, so itā€™s a js parser) into html files. But you lose all the goodies of dash, dbc and daq.

Thanks for your reply.

I agree with you about the number of stars as an indication of the quality of the library. However, it is very important to me that the project stays resonably active and it seems to me that django-plotly-dash is not active enough; even the GibbsConsulting website shows 2018 is their credits, I know this is just a label.

In order to find a solution, I am using, in addition to Django, a debian instance with Nginx and Gunicorn . In this project I could take my first steps with Flask but I need it to be on the same Debian, Nginx, Gunicorn platform.

It sounds interesting to me to use Flask in front of Django but I donā€™t know anything about how these two frameworks can be integrated. Do you know any documentation, guides, videos or any other material that I can consult to try to obtain a Django-Flask solution (Flask-PlotyDash). I guess there are many aspects that need to be resolved (security, authentication, data capture, etc).

My project is the implementation of an IoT dashbaord so dash, daq and dbc are necessary for me.

I appreciate in advance any suggestion, material or support to move forward with my project.

Iā€™m not familiar with Debian, Nginx and Gunicorn. I use Azure for the deployment. But you might find this helpful?

I have to admit, Django is very useful for the db management (save, update, create new, delete, nested data, ā€¦) and the admin tool is just fantastic. So keep it as is. But I donā€™t think that you can run Flask and Django in the same environment.

I suggest that you have 2 separate environment that communicate with html requests. You keep the hardore stuff in the backend in Django, and create views to allow your front to access what is needed. Your front will only be a gui, doesnā€™t do much crunching or db queries, it will just ask the backend to do that and send the finished product (usually a nested dict). You may need a cache in the backend, so that you can do continuous work on the same object in the backend through the front end, and enjoy the power of OOP through http.

If you need code for a simple homemade cache I have one.

This will also help you close the backend as a blackbox, a microservice, accessible through other apps. Letā€™s say you finished with your app, and wanna make a new one but not accessible to the previous client. You either copy paste the core stuff into a new backend, or you just add an app to the existing one and make a new front end (where you manage the login part). if your project blows out of proportion, then you should probably split the backend into two separate restful apis.

You can restrict access to your backend through url too (only front server and your computer) so that your stuff is safe. The front can only request what you put in the views and you can still be admin of the db.

You can maybe run the two environments in different ports of the same url through one single main.py, but that doesnā€™t seem right.

1 Like