Skip to content

Commit 5b17da8

Browse files
committed
Add docker example
1 parent e82fe72 commit 5b17da8

File tree

6 files changed

+65
-1
lines changed

6 files changed

+65
-1
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,16 @@ shiny run basic_app/app.py
2828
## Templates
2929

3030
* [posit-dev/py-shiny-templates](https://github.com/posit-dev/py-shiny-templates)
31+
32+
## Deployment
33+
34+
To run Shiny apps in production you should use `gunicorn` or `uvicorn`:
35+
36+
```bash
37+
uv add gunicorn
38+
39+
shiny create -d basic_app_core -t basic-app -m core
40+
41+
gunicorn basic_app_core.app:app -w 4 -k uvicorn.workers.UvicornWorker
42+
```
43+

basic_app_core/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:3.11
2+
3+
RUN pip install -U pip shiny gunicorn
4+
5+
COPY app.py /opt/shiny/app.py
6+
7+
EXPOSE 3333
8+
9+
CMD ["gunicorn", "opt.shiny.app:app", "-w 4", "-k uvicorn.workers.UvicornWorker", "-b 0.0.0.0:3333"]
10+

basic_app_core/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Basic App Core
2+
3+
```bash
4+
docker build -t shiny-for-py/basic-app-core:1.0.0 .
5+
6+
docker run -p 3333:3333 --rm -d shiny-for-py/basic-app-core:1.0.0
7+
```
8+

basic_app_core/app.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from shiny import App, render, ui
2+
3+
app_ui = ui.page_fluid(
4+
ui.panel_title("Hello Shiny!"),
5+
ui.input_slider("n", "N", 0, 100, 20),
6+
ui.output_text_verbatim("txt"),
7+
)
8+
9+
10+
def server(input, output, session):
11+
@render.text
12+
def txt():
13+
return f"n*2 is {input.n() * 2}"
14+
15+
16+
app = App(app_ui, server)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ description = "Add your description here"
55
readme = "README.md"
66
requires-python = ">=3.9"
77
dependencies = [
8+
"gunicorn>=23.0.0",
89
"shiny>=1.2.1",
910
]

uv.lock

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)