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

dash docs and example #94

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ parts:
- file: apps/panel
- file: apps/chainlit
- file: apps/gradio
- file: apps/docker
- file: apps/shiny-express
- file: apps/dash
- file: apps/docker
- file: apps/chalk-it

- caption: App examples
Expand Down
43 changes: 43 additions & 0 deletions doc/apps/dash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Dash

To deploy a [Dash](https://dash.plotly.com/) application to Ploomber Cloud you need:

- A `Dockerfile`
- A Dash project

## `Dockerfile`

Use this [template](https://github.com/ploomber/doc/blob/main/examples/dash/simple-app/Dockerfile) `Dockerfile`:

```Dockerfile
FROM python:3.11

COPY app.py app.py
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

ENTRYPOINT ["gunicorn", "app:server", "run", "--bind", "0.0.0.0:80"]
```

## Testing locally

To test your app, you can use `docker` locally:

```sh
# build the docker image
docker build . -t dash-app

# run it
docker run -p 5000:80 dash-app
```

Now, open [http://0.0.0.0:5000/](http://0.0.0.0:5000/) to see your app.


## Deploy

Once you have all your files, create a zip file.

To deploy a Dash app from the deployment menu, select the Docker option and follow the instructions:

![](../static/docker.png)
7 changes: 7 additions & 0 deletions examples/dash/simple-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM python:3.11

COPY app.py app.py
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt

ENTRYPOINT ["gunicorn", "app:server", "run", "--bind", "0.0.0.0:80"]
27 changes: 27 additions & 0 deletions examples/dash/simple-app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Taken from Dash's documentation: https://dash.plotly.com/minimal-app
"""
from dash import Dash, html, dcc, callback, Output, Input
import plotly.express as px
import pandas as pd

df = pd.read_csv(
"https://raw.githubusercontent.com/plotly/datasets/master/gapminder_unfiltered.csv"
)

app = Dash(__name__)
server = app.server

app.layout = html.Div(
[
html.H1(children="Population by country", style={"textAlign": "center"}),
dcc.Dropdown(df.country.unique(), "Canada", id="dropdown-selection"),
dcc.Graph(id="graph-content"),
]
)


@callback(Output("graph-content", "figure"), Input("dropdown-selection", "value"))
def update_graph(value):
dff = df[df.country == value]
return px.line(dff, x="year", y="pop")
Binary file added examples/dash/simple-app/app.zip
Binary file not shown.
4 changes: 4 additions & 0 deletions examples/dash/simple-app/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dash
plotly
pandas
gunicorn
Loading