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

Showcase filenames #2593

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

Showcase filenames #2593

wants to merge 2 commits into from

Conversation

cpsievert
Copy link
Collaborator

@cpsievert cpsievert commented Sep 10, 2019

(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)

Copy link
Contributor

@trestletech trestletech left a 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.

R/showcase.R Show resolved Hide resolved
R/showcase.R Outdated Show resolved Hide resolved
@cpsievert cpsievert requested a review from wch September 10, 2019 19:02
Copy link
Contributor

@trestletech trestletech left a 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/showcase.R Outdated Show resolved Hide resolved
R/showcase.R Show resolved Hide resolved
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"
Copy link
Collaborator

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.

Copy link
Collaborator Author

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

shiny/R/app.R

Line 95 in 4b2e6fc

shinyOptions(appDir = getwd())

@@ -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")
Copy link
Collaborator

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:

shiny/R/server.R

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.

Copy link
Collaborator Author

@cpsievert cpsievert Sep 12, 2019

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:

shiny/R/app.R

Line 224 in b889b0d

shinyOptions(appDir = appDir)

That said, it's interesting/concerning that shinyAppDir_appR doesn't set the same option...

Copy link
Collaborator Author

@cpsievert cpsievert Sep 12, 2019

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?

Copy link
Collaborator Author

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

@CLAassistant
Copy link

CLAassistant commented Oct 2, 2019

CLA assistant check
All committers have signed the CLA.

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.

Showcase mode won't display files with spaces in the name
4 participants