Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### New features

* `shiny run` now takes a `--reload-dir <DIR>` argument that indicates a directory `--reload` should (recursively) monitor for changes, in addition to the app's parent directory. Can be used more than once. (#353)

### Bug fixes

### Other changes
Expand Down
25 changes: 24 additions & 1 deletion shiny/_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import copy
import importlib
import importlib.util
import inspect
import os
import platform
import re
Expand Down Expand Up @@ -77,6 +78,14 @@ def main() -> None:
default=False,
help="Enable auto-reload, when these types of files change: .py .css .js .html",
)
@click.option(
"--reload-dir",
"reload_dirs",
multiple=True,
help="Indicate a directory `--reload` should (recursively) monitor for changes, in "
"addition to the app's parent directory. Can be used more than once.",
type=click.Path(exists=True),
)
@click.option(
"--ws-max-size",
type=int,
Expand Down Expand Up @@ -121,6 +130,7 @@ def run(
port: int,
autoreload_port: int,
reload: bool,
reload_dirs: tuple[str, ...],
ws_max_size: int,
log_level: str,
app_dir: str,
Expand All @@ -133,6 +143,7 @@ def run(
port=port,
autoreload_port=autoreload_port,
reload=reload,
reload_dirs=list(reload_dirs),
ws_max_size=ws_max_size,
log_level=log_level,
app_dir=app_dir,
Expand All @@ -147,6 +158,7 @@ def run_app(
port: int = 8000,
autoreload_port: int = 0,
reload: bool = False,
reload_dirs: Optional[list[str]] = None,
ws_max_size: int = 16777216,
log_level: Optional[str] = None,
app_dir: Optional[str] = ".",
Expand Down Expand Up @@ -227,7 +239,18 @@ def run_app(

log_config: dict[str, Any] = copy.deepcopy(uvicorn.config.LOGGING_CONFIG)

if reload_dirs is None:
reload_dirs = []

if reload:
# Always watch the app_dir
if app_dir:
reload_dirs.append(app_dir)
# For developers of Shiny itself; autoreload the app when Shiny package changes
if os.getenv("SHINY_PKG_AUTORELOAD"):
shinypath = Path(inspect.getfile(shiny)).parent
reload_dirs.append(str(shinypath))

if autoreload_port == 0:
autoreload_port = _utils.random_port(host=host)

Expand All @@ -249,7 +272,7 @@ def run_app(
"reload": reload,
# Adding `reload_includes` param while `reload=False` produces an warning
# https://github.com/encode/uvicorn/blob/d43afed1cfa018a85c83094da8a2dd29f656d676/uvicorn/config.py#L298-L304
"reload_includes": ["*.py", "*.css", "*.js", "*.html"],
"reload_includes": ["*.py", "*.css", "*.js", "*.htm", "*.html", "*.png"],
"reload_dirs": reload_dirs,
}

Expand Down