From 4d9ff7ae501b7619fce47226397892e73f97e1db Mon Sep 17 00:00:00 2001 From: Latent Date: Tue, 10 Dec 2024 13:21:30 -0500 Subject: [PATCH 1/5] [Doc] Deploy `Vizro` apps --- doc/_toc.yml | 1 + doc/apps/vizro.md | 101 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 doc/apps/vizro.md diff --git a/doc/_toc.yml b/doc/_toc.yml index 1c49e687..a7e23b62 100644 --- a/doc/_toc.yml +++ b/doc/_toc.yml @@ -45,6 +45,7 @@ parts: - file: apps/docker - file: apps/chainlit - file: apps/hyperdiv + - file: apps/vizro - caption: APIs chapters: diff --git a/doc/apps/vizro.md b/doc/apps/vizro.md new file mode 100644 index 00000000..8e8d5871 --- /dev/null +++ b/doc/apps/vizro.md @@ -0,0 +1,101 @@ +--- +myst: + html_meta: + description: Deploy a Vizro app on Ploomber in seconds with this guide. + keywords: vizro, deployment, hosting + property=og:title: Vizro | Ploomber Docs + property=og:description: Deploy Vizro app on Ploomber in seconds with this guide. + property=og:image: https://docs.cloud.ploomber.io/en/latest/_static/opengraph-images-vizro.png + property=og:url: https://docs.cloud.ploomber.io/en/latest/apps/vizro.html +--- + +# Vizro + +To deploy a [Vizro](https://vizro.readthedocs.io/en/stable/) application you need a [Ploomber Cloud](https://platform.ploomber.io/register?utm_source=dash&utm_medium=documentation) account. + +## Project Structure + +Your deployment package must include these three essential files: + +1. `app.py` - Main application file +2. `requirements.txt` - Python dependencies +3. `Dockerfile` - Container configuration + +You can get started quickly using our template repository. + +## Application Setup + +1. Main Application File (`app.py`) + +Your `app.py` should initialize the Vizro application as follows: + +```python +import vizro as vm +from vizro import Vizro + +# Initialize your dashboard +dashboard = vm.Dashboard(pages=[page]) + +# Create the application instance +app = Vizro().build(dashboard) + +# Development server (optional) +if __name__ == "__main__": + app.run() +``` + +2. Dependencies File (`requirements.txt`) + +List all Python packages required by your application. + +3. `Dockerfile` + +Create a `Dockerfile` with this configuration: + +```Dockerfile +FROM python:3.11-slim + +WORKDIR /app + +# Install dependencies +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt gunicorn vizro + +# Copy application files +COPY . . + +# Configure the container +EXPOSE 80 +CMD ["gunicorn", "--bind", "0.0.0.0:80", "--workers", "4", "--threads", "2", "app:app"] +``` + +## Testing locally + +Before deployment, test your application locally using Docker: + +```sh +# build the docker image +docker build . -t vizro-app + +# run it +docker run -p 5000:80 vizro-app +Now, open http://0.0.0.0:5000/ to see your app. +``` + +Once running, access your application at http://localhost:5000 + +## Deploy + +Deployment Process + +1. Zip all project files (`app.py`, `requirements.txt`, `Dockerfile`, and any additional resources) +2. Log in to Ploomber Cloud +3. Navigate to the deployment menu +4. Select the Docker deployment option +5. Upload your zip file + +![](../static/docker.png) + +```{tip} +To ensure your app doesn't break on re-deployments, pin your [dependencies.](pin-dependencies) +``` From 0940b57fc45d4bcde166223c2c1a7d4e2c676ee3 Mon Sep 17 00:00:00 2001 From: Latent Date: Tue, 10 Dec 2024 13:32:30 -0500 Subject: [PATCH 2/5] [Doc] Vizro Template --- doc/apps/vizro.md | 4 +++- doc/static/opengraph/opengraph-images-vizro.png | Bin 0 -> 3933 bytes 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100755 doc/static/opengraph/opengraph-images-vizro.png diff --git a/doc/apps/vizro.md b/doc/apps/vizro.md index 8e8d5871..2234e59a 100644 --- a/doc/apps/vizro.md +++ b/doc/apps/vizro.md @@ -21,7 +21,9 @@ Your deployment package must include these three essential files: 2. `requirements.txt` - Python dependencies 3. `Dockerfile` - Container configuration -You can get started quickly using our template repository. +```{note} +You can get started quickly using our [template repository](https://github.com/ploomber/doc/tree/main/examples/docker/vizro) +``` ## Application Setup diff --git a/doc/static/opengraph/opengraph-images-vizro.png b/doc/static/opengraph/opengraph-images-vizro.png new file mode 100755 index 0000000000000000000000000000000000000000..fb7624b922391d9e4b294d9068f47f8ab958b7b2 GIT binary patch literal 3933 zcmY*cc|6qX_n%=fva4h)8D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hJGo>m z4Mt)Ji$ z*!){29lC|{@$cAu1ct*}e}54qkN}M2O{pjs3>%pzOLKf78#%eh2mx4<5dlg)tYEES#~tds^{$;jPc;NKZy(Sh%AEKKoTtS9KW5$2KK8 zyfk!J&(yhZ)bEnTnxtV1ee@$MZ;gR4QbD%p+SE4X4do4A)A})X;|BP))d5jfscgLukgZF**l^;1EmaU} z-tYn-aS|Bqw=A<{o~!)GR}i02`Ueeu$=rmoZC6*cRn)Aco7&VmbXU>8bj02S8zesK z4verH6-Fa)`*e_)r>j{wU53y1B=ve1GEgMrhghSdK{@{&xedpxQQWT=WDjn;EN#sg zIiR24k1)YHh+!n~z?o_}%vkKO{soVql_m|7Yv=KpVIng+cgIA}O~kqqs_`Rh-GKe6 zhb_G3Q@NT~3Vx_><}ZR=b&-m%5^CQIU*mB4<@7RB!OF(1l=SMnMeas?^foe()87Hw zFds*0peuvIJWUN%cfjBWKHD9h0+T>M)>kBN9Ft4vc3e^k&JiLjpuUO%A>hOmL{MJ) z9&F9wGKqOsR%Fqv9#QpVMq(ypV%6u$5mCa{j5#4S=<%#{*4I8$i1d2yO16m@ z1WR@ni|+b6_z1kSeCh3FE@;E=v1s_}gsD`B@G|CrL=(&BG4CPtn2)&7Prd1??mQpj z{^g7(rEyE!UkD3GOae;_gV{Et`E}ryEi|^+%B2n0y(nQoSU;$C_k~PJq-uyyLFi3c zHud`G-;@1kRxFLTbdnBLU*F)|>#cphRN;lxJmj%jO6Yp@2bbY%fopWIUYpN_G(Fzt zN#k>%lye0Y-w20m>O-?F7bdCmW+IKoLvQ_3o5JyL;^&9jhXXn{ e;F5d$Dx4bo^Jm`$2&ZL;i^CcFDqBJV1oD5SGfh?i literal 0 HcmV?d00001 From 168137fab5d50db137194aa00c107ef9b9371d58 Mon Sep 17 00:00:00 2001 From: Latent Date: Tue, 10 Dec 2024 13:32:36 -0500 Subject: [PATCH 3/5] [Example] Virzo Template chore: split installation process --- examples/docker/vizro/Dockerfile | 24 ++++++++++++++++++++++++ examples/docker/vizro/app.py | 23 +++++++++++++++++++++++ examples/docker/vizro/readme.md | 3 +++ examples/docker/vizro/requirements.txt | 1 + 4 files changed, 51 insertions(+) create mode 100644 examples/docker/vizro/Dockerfile create mode 100644 examples/docker/vizro/app.py create mode 100644 examples/docker/vizro/readme.md create mode 100644 examples/docker/vizro/requirements.txt diff --git a/examples/docker/vizro/Dockerfile b/examples/docker/vizro/Dockerfile new file mode 100644 index 00000000..7399398e --- /dev/null +++ b/examples/docker/vizro/Dockerfile @@ -0,0 +1,24 @@ +FROM python:3.11-slim + +# Set environment variables +ENV PYTHONUNBUFFERED=1 \ + PYTHONDONTWRITEBYTECODE=1 \ + PIP_NO_CACHE_DIR=off \ + PIP_DISABLE_PIP_VERSION_CHECK=on + +# Set work directory +WORKDIR /app + +# Install Python dependencies +RUN pip install gunicorn +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Copy project files +COPY . . + +# Expose the port +EXPOSE 8000 + +# Run the application using Gunicorn +CMD ["gunicorn", "--bind", "0.0.0.0:80", "--workers", "4", "--threads", "2", "app:app"] diff --git a/examples/docker/vizro/app.py b/examples/docker/vizro/app.py new file mode 100644 index 00000000..fa588e64 --- /dev/null +++ b/examples/docker/vizro/app.py @@ -0,0 +1,23 @@ +import vizro.plotly.express as px +from vizro import Vizro +import vizro.models as vm + +df = px.data.iris() + +page = vm.Page( + title="My first dashboard", + components=[ + vm.Graph(figure=px.scatter(df, x="sepal_length", y="petal_width", color="species")), + vm.Graph(figure=px.histogram(df, x="sepal_width", color="species")), + ], + controls=[ + vm.Filter(column="species", selector=vm.Dropdown(value=["ALL"])), + ], +) + +dashboard = vm.Dashboard(pages=[page]) +app = Vizro().build(dashboard) + + +if __name__ == "__main__": + app.run() diff --git a/examples/docker/vizro/readme.md b/examples/docker/vizro/readme.md new file mode 100644 index 00000000..aa04f955 --- /dev/null +++ b/examples/docker/vizro/readme.md @@ -0,0 +1,3 @@ +# Docker Deployment with Virzo App + +Template Dockerfile and Vizro app to deploy on Ploomber Cloud. diff --git a/examples/docker/vizro/requirements.txt b/examples/docker/vizro/requirements.txt new file mode 100644 index 00000000..6f996cb0 --- /dev/null +++ b/examples/docker/vizro/requirements.txt @@ -0,0 +1 @@ +vizro==0.1.29 From c035bdce7064fcf2dc56e573dd3838dea00da290 Mon Sep 17 00:00:00 2001 From: Latent Date: Tue, 10 Dec 2024 15:21:32 -0500 Subject: [PATCH 4/5] [Example] Start the Flask server directly | otherwise, warning in the logs --- examples/docker/vizro/Dockerfile | 2 +- examples/docker/vizro/app.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/docker/vizro/Dockerfile b/examples/docker/vizro/Dockerfile index 7399398e..6af91596 100644 --- a/examples/docker/vizro/Dockerfile +++ b/examples/docker/vizro/Dockerfile @@ -21,4 +21,4 @@ COPY . . EXPOSE 8000 # Run the application using Gunicorn -CMD ["gunicorn", "--bind", "0.0.0.0:80", "--workers", "4", "--threads", "2", "app:app"] +ENTRYPOINT ["gunicorn", "app:server", "run", "--bind", "0.0.0.0:80"] diff --git a/examples/docker/vizro/app.py b/examples/docker/vizro/app.py index fa588e64..ba378f7f 100644 --- a/examples/docker/vizro/app.py +++ b/examples/docker/vizro/app.py @@ -17,7 +17,7 @@ dashboard = vm.Dashboard(pages=[page]) app = Vizro().build(dashboard) - +server = app.dash.server if __name__ == "__main__": app.run() From b5f98a850ab61e00dea156cffb58ec0e85a925e7 Mon Sep 17 00:00:00 2001 From: Latent Date: Tue, 10 Dec 2024 15:21:41 -0500 Subject: [PATCH 5/5] [Doc] Start the Flask server directly | otherwise, warning in the logs --- doc/apps/vizro.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/apps/vizro.md b/doc/apps/vizro.md index 2234e59a..0d8b31be 100644 --- a/doc/apps/vizro.md +++ b/doc/apps/vizro.md @@ -41,6 +41,9 @@ dashboard = vm.Dashboard(pages=[page]) # Create the application instance app = Vizro().build(dashboard) +# Expose the Flask server to Gunicorn +server = app.dash.server + # Development server (optional) if __name__ == "__main__": app.run() @@ -68,7 +71,7 @@ COPY . . # Configure the container EXPOSE 80 -CMD ["gunicorn", "--bind", "0.0.0.0:80", "--workers", "4", "--threads", "2", "app:app"] +ENTRYPOINT ["gunicorn", "app:server", "run", "--bind", "0.0.0.0:80"] ``` ## Testing locally