Possible to embed a plot.ly Dash app (flask app) in Anvil?

I’m working on a plot.ly Dash app, which is essentially a self-contained Flask app and distinct from plot.ly charts, and am curious to know if it is possible to call/embed this app in Anvil.

Dash does allow for one to embed the app as an iFrame but for a variety of reasons I’d like to avoid this. As I’m familiar with Anvil I would prefer to use it for user auth/billing rather than learning Flask from the ground up.

So, is it at all possible to run a Flask app inside of Anvil?

Hi Ben,

Flask runs a web server so running it in the Anvil backend environment is not supported.

I would use an IFrame for this - what makes you want to avoid them? If you don’t want to embed your Dash app in an Anvil app, you could embed an Anvil app in your Dash app…

You might be able to use HTTP Endpoints or a HTTP redirect to get what you want. What specifically do you want to do with the Anvil part of the system?

Hi Shaun,

Thanks for the reply. As far as the use case for Anvil, I’d like it to serve as the host site for the dash, to include all non-dashboard content, user sign up/authentication, subscription/billing management, etc.

I was hoping to avoid using an iFrame because I’d like to limit the dashboard to authorized users only and its not difficult for someone to sniff out the source url for the iFrame, even if it is obfuscated. That said, Plotly Dash includes some built-in authentication features so I might be able to use those.

I’ll read up on HTTP Endpoints as I’m not familiar with them at the moment.

I mentioned HTTP endpoints in case you just wanted to use back-end functions and drive them from Dash. You could wrap them in HTTP endpoints and call them from Dash - that way, you use Anvil’s familiar user management and billing. Sounds like you want to use Anvil for UI though, so it’s not the way to go.

I’m wondering if you could use Anvil as a gateway to the dashboard - create an app that has the login form and an account management section for billing etc., then link to your Dash app. You could host them at the same domain: https://example.com for the Anvil gateway and https://data.example.com for the dashboard itself.

I was hoping to avoid using an iFrame because I’d like to limit the dashboard to authorized users only and its not difficult for someone to sniff out the source url for the iFrame, even if it is obfuscated. That said, Plotly Dash includes some built-in authentication features so I might be able to use those.

Yes, perhaps you can use a session token that you include in the src of the IFrame so even if they did sniff out the URL for the IFrame, they would only be able to access the Dash while their token was valid.

These are both good ideas. I’m going to tinker a bit and see what I can come up with.

Many thanks!

1 Like