App-Packages
The first section of the book took pyap from a single app.py file to an installable Python package. This section fills that package in. Expand the callout boxes below to review what we covered in the last four chapters:
Where we are
At the end of the 04_dev branch, pyap has the structure below:
pyap/
├── .gitignore
├── .python-version
├── .vscode/
│ └── settings.json
├── README.md
├── movies.csv
├── pyproject.toml
├── src/
│ └── pyap/
│ ├── __init__.py
│ ├── app.py
│ └── utils.py
└── uv.lock
The package installs and the app runs, but a few loose ends remain. The functions in utils.py have no documentation, movies.csv sits outside the package and is only found when we launch the app from the project root, and we still start the app by pointing shiny run at a file path. The chapters in this section address each of these with the edit, sync, and run loop from the Development Workflow chapter.
What’s ahead
Documentation covers writing docstrings for the functions in pyap and generating HTML documentation from them with pdoc, mkdocs, or great-docs. In R, roxygen2 comments are rendered into help files with document(); Python reads docstrings directly, so the work is mostly in writing them well.
Dependencies covers declaring, pinning, and managing the packages pyap depends on in pyproject.toml, and keeping environments reproducible across machines with uv add, uv lock, and uv sync.
Data moves movies.csv inside the package and reads it with importlib.resources, so the file is found no matter where pyap is installed or which folder the app is launched from.
Launch defines an entry point in [project.scripts], so users can start the app with a single command instead of calling shiny run on a path inside src/pyap/.
Resources covers including static files (CSS, JavaScript, images, and HTML templates) in the package and serving them from the Shiny app.
By the end of this section, pyap will be a self contained app-package: documented, reproducible, carrying its own data and assets, and launchable from the command line. The Debugging and Testing sections build on this foundation.