Skip to content

Commit

Permalink
use shinyOption() to set/get app filename
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert committed Sep 11, 2019
1 parent e5dcd5e commit 4691129
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
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")
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
5 changes: 2 additions & 3 deletions R/showcase.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ 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 "",
li(class=if (identical(file, getShinyOption("appFile"))) "active" else "",
a(href=paste0("#", gsub("\\.|\\s+", "_", file), "_code"),
"data-toggle"="tab", paste0(prefix, file)))
)
Expand All @@ -106,8 +106,7 @@ tabContentHelper <- function(files, path, language) {
lapply(files, function(file) {
with(tags,
div(class=paste0("tab-pane",
# TODO: what if the app filename is something else?
if (tolower(file) %in% c("app.r", "server.r")) " active"
if (identical(file, getShinyOption("appFile"))) " active"
else ""),
id=paste0(gsub("\\.|\\s+", "_", file), "_code"),
pre(class="shiny-code",
Expand Down

0 comments on commit 4691129

Please sign in to comment.