From e5dcd5e5745bc2ae8ca3f55187d54a28c6622a02 Mon Sep 17 00:00:00 2001 From: Carson Date: Mon, 9 Sep 2019 17:49:33 -0500 Subject: [PATCH 1/2] Replace spaces with underscores when mapping filenames to ids in the showcase, closes #1926 --- R/showcase.R | 11 +++++------ inst/www/shared/shiny-showcase.js | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/R/showcase.R b/R/showcase.R index d215f90eef..c500287450 100644 --- a/R/showcase.R +++ b/R/showcase.R @@ -82,7 +82,7 @@ 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=""), + a(href=paste0("#", gsub("\\.|\\s+", "_", file), "_code"), "data-toggle"="tab", paste0(prefix, file))) ) }) @@ -105,12 +105,11 @@ navTabsDropdown <- function(files) { tabContentHelper <- function(files, path, language) { lapply(files, function(file) { with(tags, - div(class=paste("tab-pane", + div(class=paste0("tab-pane", + # TODO: what if the app filename is something else? if (tolower(file) %in% c("app.r", "server.r")) " active" - else "", - sep=""), - id=paste(gsub(".", "_", file, fixed=TRUE), - "_code", sep=""), + else ""), + id=paste0(gsub("\\.|\\s+", "_", file), "_code"), pre(class="shiny-code", # we need to prevent the indentation of ... HTML(format(tags$code( diff --git a/inst/www/shared/shiny-showcase.js b/inst/www/shared/shiny-showcase.js index 6c1085e46f..680f667da0 100644 --- a/inst/www/shared/shiny-showcase.js +++ b/inst/www/shared/shiny-showcase.js @@ -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]); From 469112962f1c4e4c736bf3a922926a6f216fc05d Mon Sep 17 00:00:00 2001 From: Carson Date: Wed, 11 Sep 2019 13:10:04 -0500 Subject: [PATCH 2/2] use shinyOption() to set/get app filename --- R/app.R | 3 +++ R/showcase.R | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/R/app.R b/R/app.R index b1d8f17d7a..90200176c7 100644 --- a/R/app.R +++ b/R/app.R @@ -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.") @@ -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) } diff --git a/R/showcase.R b/R/showcase.R index c500287450..930482cd04 100644 --- a/R/showcase.R +++ b/R/showcase.R @@ -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))) ) @@ -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",