mckinsey / vizro

Vizro is a toolkit for creating modular data visualization applications.
https://vizro.readthedocs.io/en/stable/
Apache License 2.0
2.49k stars 112 forks source link

How to integrate with other applications like flask, frappe or django? #317

Open KathirvelPriya opened 5 months ago

KathirvelPriya commented 5 months ago

Question

How to integrate with other applications like flask, frappe or django?

Code/Examples

No response

Other information

No response

Which package?

None

Package version

No response

Python version

No response

OS

No response

Code of Conduct

antonymilne commented 5 months ago

Hi @KathirvelPriya, thanks for your question. Under the hood, Vizro wraps Dash, which itself wraps a Flask app. Hence your question is basically the same as asking how to integrate a Dash app into a web framework.

If you search for how to integrate a Dash app into a web framework then you'll find lots of discussion of it e.g. on the plotly forums. Here's some pointers though:

Here's a very simple working example of Vizro inside an existing Flask app (which, as discussed in this article, might not be the way you actually want to do it, but serves as a good proof of concept).

import flask
import vizro
import vizro.models as vm

server = flask.Flask(__name__)

@server.route("/")
def home():
    return "Hello, Flask!"

page = vm.Page(title="My first page", components=[vm.Card(text="Hello, Vizro!")])
dashboard = vm.Dashboard(pages=[page])

app = vizro.Vizro(server=server, routes_pathname_prefix="/dashboard/").build(dashboard)
app.run()

http://127.0.0.1:8050/ gives the Flask app: image

http://127.0.0.1:8050/dashboard/ gives the Vizro app: image

KathirvelPriya commented 5 months ago

Hi @antonymilne, Thanks for your reply. I want to integrate with Frappe. I referred plotly-frappe-dash before. But it couldn't help in latest version of frappe.

antonymilne commented 5 months ago

Ah, that's a pity. I recommend posting on the plotly forums to see if they can help you with that. Basically if you can get it working with pure Dash then you should easily be able to get it working with Vizro. And if you can't get it working with pure Dash then unfortunately you won't be able to get it working with Vizro.

KathirvelPriya commented 5 months ago

Thank you for your response. I will try.