I’m building a web app with Flask that embeds a few Dash graphs via iframes. Each of the graphs has multiple dropdowns for filtering. Because of the multiple dropdowns, I’d like to be able to open the page with the Dash graph to specify and change the default dropdown values to immediately display a specific slice of the data. E.g. the user hits myapp.com/dash?location=london and the dash app is loaded with Location dropdown set to “London”.
I’m having trouble with this and I suspect it’s because I haven’t been able to pass attributes from the iframe to Dash itself. I can create a simple callback that correctly updates the default value:
And then I’d pass location to the iframe with something like this in JS:
var iframe = document.getElementById("dash-iframe");
iframe.contentWindow.postMessage({ attributeValue: "{{location}}" }, "*");
So I think what I need is a way to access location from the iframe in my update_dropdown_default callback. This is where I’m struck. Does anyone know how I can do that? Should I be thinking about this an entirely different way? Can share more details if needed.
You wouldnt need a callback assuming that everything is working properly when your layout is loading.
Now, this might be a little slower than a regular callback because of how things are going. But… you can control an element in the template easier than dealing with cross-site and non-same domain names trying to send info to the page.
If however, you wanted to migrate your my_graph template over to Dash, that would work well too.
Dash is built on-top of Flask, so integration is possible.
When you say I wouldn’t need a callback, does that mean http://localhost:8050?location=london will automatically set my “location” dropdown to “london”? I just tried that and it didn’t seem to work (but maybe I did something wrong).
And thanks for the point on integrating with my flask app. I’ve been wondering if that’s the route I should go anyways.
Sorry, I should have mentioned I’m not using the official “Page” construct. I’m new to dash and haven’t come across that before.
Tomorrow I’m going to look at integrating the dash apps with my flask app, in case that’s a better solution than iframes. thanks for your help in the meantime.