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

feat: Fully reload ui/server when autoreload occurs #4184

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

gadenbuie
Copy link
Member

@gadenbuie gadenbuie commented Feb 3, 2025

This PR updates the auto reload to fully reload both the UI and server source code when any change is detected in the watched autoreload files.

Previously, auto reload would trigger a refresh of the app but the UI or server functions would be updated only if the ui.R or server.R files themselves changed (or both if using a single-file app source).

This PR updates auto reloading so that any change to the files matching shiny.autoreload.pattern causes both the UI and server source to be reloaded.

This fixes two long-standing open issues:

Fixes #2711
Fixes #1142

Example app

For testing, the following app sources R files and uses stylesheets outside the main app.R. Currently, in main, any changes to the supporting files causes the app to be reloaded but the reloaded app does not reflect the changes.

After this PR, changes to support files are reflected after the reload.

Example app on shinylive.

TODO

@gadenbuie gadenbuie requested a review from jcheng5 February 3, 2025 23:05
jcheng5
jcheng5 previously approved these changes Feb 21, 2025
* feat: Use {watcher}

* chore: shikokuchuo/watcher@dev

* chore: watcher is on CRAN now

* chore: Undo air format changes

* feat: Use `shiny.autoreload.interval` for watcher latency

* chore: Simply track last time auto-reload changed

* docs: rewrite options docs for clarity
@gadenbuie gadenbuie requested a review from jcheng5 February 28, 2025 13:43
@gadenbuie gadenbuie dismissed jcheng5’s stale review February 28, 2025 13:44

Updated since approved, changes now include reloading global+support files in ui/server apps

@gadenbuie
Copy link
Member Author

@jcheng5 Can you take another quick look at this PR? After testing I realized that it's equally confusing not to load changes in global.R if you're using the ui.R/server.R app style. These changes add support for reloading those files when shiny.autoreload.r is TRUE: https://github.com/rstudio/shiny/pull/4184/files/aa4a609c4d82de5860522c986bae514836bb01ad..f52efec17ae08e2bf87279a2b8e58cb5914d219c

DESCRIPTION Outdated
Comment on lines 96 to 97
lifecycle (>= 0.2.0),
watcher
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would feel better if watcher wasn't a hard requirement because of its somewhat non-standard system dependencies for building from source.

We do, unfortunately, have lots of users/customers running older versions of R where binaries won't be available

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we want to go all the way to this end, but in b3f2948 I restored the legacy autoreload behavior and moved watcher to suggests, with a warning to install watcher for an improved experience.

Comment on lines +343 to +352
if (!isFALSE(getOption("shiny.autoreload.legacy_warning", TRUE))) {
cli::cli_warn(
c(
"Using legacy autoreload file watching. Please install {.pkg watcher} for a more performant autoreload file watcher.",
"i" = "Set {.run options(shiny.autoreload.legacy_warning = FALSE)} to suppress this warning."
),
.frequency = "regularly",
.frequency_id = "shiny.autoreload.legacy_warning"
)
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpsievert Should this use get_devmode_option()? And if so, what would that look like?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, I don't think shiny.autoreload.legacy_warning should be documented anywhere, but I do envision someone wanting to suppress the message entirely if they don't want to use watcher.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seem like get_devmode_option() is necessary. The only reason to use it is if you want the option's default to be different when devmode(TRUE) is activated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

autoreload doesn't load with Shiny modules Autoreload does not load css files
3 participants