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

Can this be made to work with a Flask app linked to 2 Dash apps? #3

Closed
rxavier opened this issue Jul 23, 2021 · 3 comments
Closed

Can this be made to work with a Flask app linked to 2 Dash apps? #3

rxavier opened this issue Jul 23, 2021 · 3 comments

Comments

@rxavier
Copy link

rxavier commented Jul 23, 2021

Hi @oegedijk! Thank you so much for your work, it's very promising.

I've tested it with one of my Dash apps and it's working flawlessly.

However, I wanted to use this functionality for a project of mine which is based on a Flask app which links to 2 different Dash apps. In that case, I couldn't get the querystrings to work (the URL didn't update, and URL parameters weren't passed to components).

My workflow is a bit different, since I'm passing the Flask server to the Dash class. Then when the Flask app is created, the dashboards are added within a Flask app_context.

While moving to a pure Dash environment is viable (the projected started in Flask and then evolved to include Dash apps, which is why it has its current setup), I would need to keep both Dash apps working simultaneously. From what I've been reading (1, 2), no one has managed to make these workarounds work for multi-app setups.

So I was wondering if this is something you have faced and if you've found any solutions.

@oegedijk
Copy link
Owner

Hi @rxavier,

Glad it was helpful, and that you were able to get it to work! In terms of multi page apps with querystrings, I have not really worked with that myself, so don't have any helpful advice to share unfortunately...

Does the URL not get passed in general, or is it just in a different format? Another way of asking, is what does Input('url', 'href') return?

@rxavier
Copy link
Author

rxavier commented Jul 26, 2021

I think I figured it out. It's not about the fact there's 2 Dash apps (I thought that would be, since I've seen in other threads people mentioning that limitation of other solutions similar to yours), and it's not about the main app being Flask and then Dash receiving the Flask server to piggy-back off of.

It's the use of iFrames to load Dash apps.

A bit more info:

  1. I have a Flask app with a couple jinja templates that extend each other.
  2. When I wanted to add a Dash dashboard, I wanted to keep my layouts (navigation bar, logo, footer, etc)
  3. The only way I know how to do that is to load the Dash app into an existing HTML layout with an iFrame (https://github.com/rxavier/econuy-web/blob/master/econuy_web/templates/overview.html), where dash_url is the url_base_pathname from the Dash class.
  4. So when I go to the URL that contains the iFrame, it doesn't match the url_base_pathname.
  5. If I go and load the Dash app directly from the URL at url_base_pathname (not the URL that contains the iFrame) it works perfectly.

I think this can be explained by dcc.Location not being able to read the URL where the iFrame is located, but I'm not sure.

I don't know if there's a way to make my setup work. In that case, I might just have to rebuild the layout with Dash components and get rid of most of the Flask setup.

@oegedijk
Copy link
Owner

Ah, that makes some sense, yes!

Also makes sense that an iframe wouldn't have access to certain things like the querystring of the parent frame...

@rxavier rxavier closed this as completed Jul 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants