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
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
3 changes: 3 additions & 0 deletions R/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -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

shinyAppDir_serverR(appDir, options = options)
} else if (file.exists.ci(appDir, "app.R")) {
shinyOptions(appFile = "app.R")
shinyAppDir_appR("app.R", appDir, options = options)
} else {
stop("App dir must contain either app.R or server.R.")
Expand All @@ -136,6 +138,7 @@ shinyAppFile <- function(appFile, options=list()) {
appFile <- normalizePath(appFile, mustWork = TRUE)
appDir <- dirname(appFile)

shinyOptions(appFile = basename(appFile))
shinyAppDir_appR(basename(appFile), appDir, options = options)
}

Expand Down
14 changes: 6 additions & 8 deletions R/showcase.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ appMetadata <- function(desc) {
navTabsHelper <- function(files, prefix = "") {
lapply(files, function(file) {
with(tags,
li(class=if (tolower(file) %in% c("app.r", "server.r")) "active" else "",
a(href=paste("#", gsub(".", "_", file, fixed=TRUE), "_code", sep=""),
li(class=if (identical(file, getShinyOption("appFile"))) "active" else "",
a(href=paste0("#", gsub("\\.|\\s+", "_", file), "_code"),
"data-toggle"="tab", paste0(prefix, file)))
)
})
Expand All @@ -105,12 +105,10 @@ navTabsDropdown <- function(files) {
tabContentHelper <- function(files, path, language) {
lapply(files, function(file) {
with(tags,
div(class=paste("tab-pane",
if (tolower(file) %in% c("app.r", "server.r")) " active"
else "",
sep=""),
id=paste(gsub(".", "_", file, fixed=TRUE),
"_code", sep=""),
div(class=paste0("tab-pane",
if (identical(file, getShinyOption("appFile"))) " active"
else ""),
cpsievert marked this conversation as resolved.
Show resolved Hide resolved
id=paste0(gsub("\\.|\\s+", "_", file), "_code"),
pre(class="shiny-code",
# we need to prevent the indentation of <code> ... </code>
HTML(format(tags$code(
Expand Down
2 changes: 1 addition & 1 deletion inst/www/shared/shiny-showcase.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
el = document.createElement("span");
el.id = "srcref_" + srcref;
var ref = srcref;
var code = document.getElementById(srcfile.replace(/\./g, "_") + "_code");
var code = document.getElementById(srcfile.replace(/\.|\s+/g, "_") + "_code");
// if there is no code file (might be a shiny file), quit early
if (!code) return;
var start = findTextPoint(code, ref[0], ref[4]);
Expand Down