{"id":14065016,"url":"https://github.com/analythium/shiny-load-balancing","last_synced_at":"2026-01-07T15:58:15.016Z","repository":{"id":65315646,"uuid":"543876437","full_name":"analythium/shiny-load-balancing","owner":"analythium","description":"Scaling and Load Balancing Shiny for R and Python Apps with Docker","archived":false,"fork":false,"pushed_at":"2024-06-01T05:53:35.000Z","size":13236,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-08-14T07:08:02.840Z","etag":null,"topics":["digitalocean-app-platform","docker","docker-compose","fly-io","heroku","load-balancing","multiple-regions","python","r","rstats","scaling"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/analythium.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-10-01T03:35:20.000Z","updated_at":"2024-06-10T11:50:36.000Z","dependencies_parsed_at":"2023-01-16T13:31:08.556Z","dependency_job_id":null,"html_url":"https://github.com/analythium/shiny-load-balancing","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/analythium%2Fshiny-load-balancing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/analythium%2Fshiny-load-balancing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/analythium%2Fshiny-load-balancing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/analythium%2Fshiny-load-balancing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/analythium","download_url":"https://codeload.github.com/analythium/shiny-load-balancing/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228046038,"owners_count":17861084,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["digitalocean-app-platform","docker","docker-compose","fly-io","heroku","load-balancing","multiple-regions","python","r","rstats","scaling"],"created_at":"2024-08-13T07:04:14.391Z","updated_at":"2026-01-07T15:58:14.974Z","avatar_url":"https://github.com/analythium.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Scaling Shiny Apps for Python and R\n\n\u003e We had high hopes for Heroku, as they have a documented option for session affinity. However, for reasons we don’t yet understand, the test application consistently fails to pass. We’ll update this page as we find out more. - [Shiny for Python docs](https://shiny.rstudio.com/py/docs/deploy.html#heroku)\n\n**Shiny for R and Python** can be [deployed](https://shiny.rstudio.com/py/docs/deploy.html) in _conventional ways_, using RStudio Connect, Shiny Server Open Source, and Shinyapps.io.\n\nWhen it comes to _alternative options_, the [docs](https://shiny.rstudio.com/py/docs/deploy.html#other-hosting-options) tell you to:\n\n- have support for _WebSockets_, and\n- use _sticky_ load balancing.\n\nThe following options support WebSockets, and deploying with Docker is straightforward Increasing the number of replicas and properly load balancing between them is trickier, but not impossible:\n\n| Hosting option  | Scaling instances  | Multiple regions  |\n|---|---|---|\n| [Heroku](./01-heroku.md)  | ✅  | ❌  |\n| [DigitalOcean App Platform](./02-do-app-platform.md)  | ❌  | ❌  |\n| [Fly.io](./03-fly.md)  | ❌  | ❓  |\n| [Docker Compose](./04-docker-compose.md)  | ✅  | ❌  |\n\n\nThis repository contains supporting material ofr the following blog posts on the _Hosting Data Apps_ ([hosting.analythium.io](https://hosting.analythium.io/)) website:\n\n- [Containerizing Shiny for Python and Shinylive Applications](https://hosting.analythium.io/containerizing-shiny-for-python-and-shinylive-applications/)\n\n## Testing sticky sessions\n\nWe build a Python and an R version of a test application to test how load balancing works. We use this [Shiny for Python test application](https://github.com/rstudio/py-shiny/blob/7ba8f90a44ee25f41aa8c258eceeba6807e0017a/examples/load_balance/app.py).\n\n### Py-Shiny app\n\nThe [test application](https://github.com/rstudio/py-shiny/blob/7ba8f90a44ee25f41aa8c258eceeba6807e0017a/examples/load_balance/app.py) is build following the [usual Docker workflow for Shiny for Python](./00-py-shiny-docker.md).\n\nWe use the `Dockerfile.lb` and the app in the [`load-balancing`](load-balancing) folder containing the `app.py` and `requirements.txt` files.\n\nBuild, test run the image, and push to Docker Hub:\n\n```bash\n# build\n# docker build -f Dockerfile.lb -t analythium/python-shiny-lb:0.1 .\ndocker buildx build --platform=linux/amd64 -f Dockerfile.lb -t analythium/python-shiny-lb:0.1 .\n\n# run: open http://127.0.0.1:8080\ndocker run -p 8080:8080 analythium/python-shiny-lb:0.1\n\n# push\ndocker push analythium/python-shiny-lb:0.1\n```\n\n\u003e If you are running your container behind a TLS Termination Proxy (load balancer) like Nginx or Caddy, add the option `--proxy-headers`, this will tell Uvicorn to trust the headers sent by that proxy telling it that the application is running behind HTTPS, etc. - [FastAPI docs](https://fastapi.tiangolo.com/deployment/docker/)\n\n### Shinylive\n\n[Shinylive](https://shiny.rstudio.com/py/docs/shinylive.html) is an experimental feature (Shiny + WebAssembly) that allows applications to run entirely in a web browser, without the need for a separate server running Python.\n\nWe use the load balancing test application and build some static assets based on the `Dockerfile-lb-live` file:\n\n```bash\n# build\n# docker build -f Dockerfile.lb-live -t analythium/python-shiny-live-lb:0.1 .\ndocker buildx build --platform=linux/amd64  -f Dockerfile.lb-live -t analythium/python-shiny-live-lb:0.1 .\n\n# run: open http://127.0.0.1:8080\ndocker run -p 8080:8080 analythium/python-shiny-live-lb:0.1\n\n# push\ndocker push analythium/python-shiny-live-lb:0.1\n```\n\nThe [`docs`](docs) folder contains the exported Shinylive site with the static HTML, which is also deployed to GitHub Pages:\n\u003chttps://hub.analythium.io/shiny-load-balancing\u003e.\n\n### R-Shiny app\n\nThe R version is a port of the Python app.\n\n```bash\n# build\n# docker build -f Dockerfile.lb-r -t analythium/r-shiny-lb:0.1 .\ndocker buildx build --platform=linux/amd64 -f Dockerfile.lb-r -t analythium/r-shiny-lb:0.1 .\n\n# run: open http://127.0.0.1:8080\ndocker run -p 8080:8080 analythium/r-shiny-lb:0.1\n\n# push\ndocker push analythium/r-shiny-lb:0.1\n```\n\n## License\n\n[MIT](LICENSE) 2022 (c) [Analythium Solutions Inc.](https://analythium.io)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanalythium%2Fshiny-load-balancing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fanalythium%2Fshiny-load-balancing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fanalythium%2Fshiny-load-balancing/lists"}