-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Showcase filenames #2593
base: main
Are you sure you want to change the base?
Showcase filenames #2593
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, looks great! I just had a couple of minor questions/concerns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One super-nitpicky question, but LGTM! 💯
R/app.R
Outdated
@@ -121,8 +121,10 @@ shinyAppDir <- function(appDir, options=list()) { | |||
appDir <- normalizePath(appDir, mustWork = TRUE) | |||
|
|||
if (file.exists.ci(appDir, "server.R")) { | |||
.globals$appFile <- "server.R" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a danger in setting .globals$appFile
in this function. It's possible for this to happen:
- This function is called and the returned shiny app object is saved (but not run).
- Another app is run and then stops.
- The first app object is run.
In this scenario, then when the original app is running, the value of .globals$appFile
will be from the other app.
A similar problem can happen if:
- An shiny app is run (and calls this function)
- Another shiny app, one that is generated by a function (and does not call this function) is run.
Then that second app will have .globals$appFile
from the first app.
So I think we need to store this information in another way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would shinyOptions()
be a decent way to ensure the filename is local to each app? Looks like we already do that to set/get the app directory here
Line 95 in 4b2e6fc
shinyOptions(appDir = getwd()) |
4b2e6fc
to
bb37ec8
Compare
bb37ec8
to
4691129
Compare
@@ -121,8 +121,10 @@ shinyAppDir <- function(appDir, options=list()) { | |||
appDir <- normalizePath(appDir, mustWork = TRUE) | |||
|
|||
if (file.exists.ci(appDir, "server.R")) { | |||
shinyOptions(appFile = "server.R") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will still be applied at the global level, so it could affect subsequent apps in the same was as .globals$appFile
would. This is because shinyAppDir
could be called directly (outside of runApp
, which creates a new layer on the options stack).
runApp
adds a new layer on the stack here:
Lines 747 to 752 in b889b0d
# Enable per-app Shiny options, for shinyOptions() and getShinyOption(). | |
oldOptionSet <- .globals$options | |
on.exit({ | |
.globals$options <- oldOptionSet | |
},add = TRUE) | |
So what I think is needed is to attach this information to the app object directly. In order to do that, I think we'll want to change shiny app objects so that they have a designated place to store extra information like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what I think is needed is to attach this information to the app object directly.
I can go in that direction if you prefer, but what about setting this option inside of shinyAppDir_appR()
and shinyAppDir_serverR()
? I only bring it up because it'd be more consistent with what's already done here with the appDir
in shinyAppDir_serverR
:
Line 224 in b889b0d
shinyOptions(appDir = appDir) |
That said, it's interesting/concerning that shinyAppDir_appR
doesn't set the same option...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case that we attach this info to the app object, would you prefer a new undocumented option? Or a new top-level field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh interesting, looks like you considered attaching appDir
in a new appConfig
field for bookmarkable state, but eventually decided against it, any idea why? f78bd08
(Best to review commit by commit)
The first commit fixes #1926
The second commit fixes what seems to be an undocumented problem when running an app file that is named something other than
app.R
in showcase mode (the app file should be 'active', that is, shown by default).See rstudio/shiny-examples#157 for a testing app illustrating both of these fixes.
(BTW, we could use this testing app for #2582 as well, if we wanted)