Dash and Django


I just found out about Dash, and it looks like lots of fun. I’ve been doing work with Django sites, and Dash looks like a good way to get JavaScript in there without having to leave Python (I know both languages, but it seems easier to stick with one language and have a library do the translating). My initial question is about pages. Django generates HTML from a template engine, but Dash app pages are their own thing. What would be the best path for me to embed a Dash app inside a page of a Django site? Would I have to use an iframe, or is there an easier Python-based answer?

Enabling authentication

Good question! For now, I think the best answer is just embedding the app as an iframe inside your templates.

If you or your company would like to sponsor a dash-django package, please reach out.


Good to know. That’s doable, but as I mentioned I’d like to keep inside Python as much as possible when the project is mostly Python. As I move forward with my personal projects, I will likely have some thoughts (which may or may not include PRs; I’m still a newbie to Python) about smoother integration with the end goal of having Dash as a pluggable Django app. From where I’m looking at it, this seems like a marriage that has to happen at some point. :slight_smile:


The thing that makes this less than ideal for me, as someone who deploys on Heroku, is that I believe I would need to spin up two apps with their own dynos; one for the Dash app, and one for the Flask app.

This was the same issue that I was having with incorporating Bokeh into a Flask app. The only way to have the interactive widgets was to spin up a Bokeh server on a separate Heroku dyno and then point to it from the Flask app.
Again - this was less than ideal.

So, I like that Dash gives me the opportunity to create a multi-page site that is all inclusive all on one dyno…
Though it means that I lose access to a ton of premade templates.


Ideally, I think I’d try to make a Django plugin that invokes a particular Dash app (named in a template tag) and pulls the generated HTML and JavaScript out to inject it into the Django page in place of that tag. I suspect that this might be slow, but that’s not an issue for me since it’s a one-time thing. I’m not sure how I’d execute this, but it sounds possible enough to investigate and all of the better solutions would involve forking Dash (I’d rather do the iframe solution forever than maintain a fork like that).

Does anyone have any thoughts on the matter?


I’ve made Dash’s front-end and component system completely modular and separate from Dash’s backend to allow for alternative Dash backends in either other languages or other servers. This opens up the possibility to implement an alternative Dash backend in something like Django. The backend just needs to parse the JSON HTTP responses and provide a nice @app.callback decorator.

Before the community starts writing alternative backends, we should stabilize, spec out, and version this API. That way, the Dash front-end ("dash-renderer": https://github.com/plotly/dash-renderer) can be versioned to be compatible with certain versions of this spec.

I’d like to wait for the dust to settle before locking these specs down and before officially supporting alternative backends. I hope that makes sense!

Again, if anyone or their company would like to expedite through sponsorship, please reach out.


Makes sense. In that case, I won’t rush to make anything substantial, but I might try to figure out how I feel a Dash integration should be used from the Django side.


@ead Posted an (unofficial) solution / workaround to serving Dash apps through Django here: Embed dash plot into web page