Skip to content

Commit

Permalink
PHS logo colour options (#103)
Browse files Browse the repository at this point in the history
* PHS logo colour options

* Style code (GHA)

---------

Co-authored-by: alan-y <[email protected]>
  • Loading branch information
alan-y and alan-y authored Dec 8, 2024
1 parent e1f0fc9 commit a2bdf1c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
18 changes: 15 additions & 3 deletions R/phsshinyapp.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#' @param path String: Filepath for the project.
#' @param author String: Name of the main author for the project.
#' @param app_name String: name of application.
#' @param phs_white_logo Logical: Use a white PHS logo.
#' @param git Logical: Initialise the project with Git.
#' @param renv Logical: Initialise the project with package management using renv.
#' @param overwrite Logical: Whether to overwrite directory at existing path when creating directory.
Expand All @@ -18,7 +19,7 @@
#' )
#' }
phsshinyapp <- function(path, author = Sys.info()[["user"]], app_name = "WRITE APP NAME HERE",
git = FALSE, renv = FALSE, overwrite = FALSE) {
phs_white_logo = TRUE, git = FALSE, renv = FALSE, overwrite = FALSE) {
# Checking if path already exists
if (dir.exists(path)) {
if (overwrite) {
Expand Down Expand Up @@ -83,6 +84,14 @@ phsshinyapp <- function(path, author = Sys.info()[["user"]], app_name = "WRITE A
app_preamble <- shiny_app_template(app_name = app_name, author = author)
app_code <- paste0(app_preamble, app_code, collapse = "\n")

if (!phs_white_logo) {
app_code <- gsub("phs-logo-white", "phs-logo", app_code)
css_code <- gsub(
"navbar-brand \\{color: var\\(--phs-purple\\); background-color: var\\(--phs-purple\\)\\}",
"navbar-brand \\{color: var\\(--phs-purple\\); background-color: var\\(--white\\)\\}",
css_code
)
}

# Write to index file
if (!renv) {
Expand Down Expand Up @@ -111,17 +120,20 @@ phsshinyapp <- function(path, author = Sys.info()[["user"]], app_name = "WRITE A
from = system.file(package = "phstemplates", "images", "phs-logo.png"),
to = file.path(path, "www", "phs-logo.png")
)
logo_white <- file.copy(
from = system.file(package = "phstemplates", "images", "phs-logo-white.png"),
to = file.path(path, "www", "phs-logo-white.png")
)
favicon <- file.copy(
from = system.file(package = "phstemplates", "images", "favicon_phs.ico"),
to = file.path(path, "www", "favicon_phs.ico")
)


if (!logo | !favicon) {
if (!logo | !favicon | !logo_white) {
message("PHS logo and favicon could not be copied. Please obtain these images for them to show in the shiny app.")
}


if (git) {
if (Sys.info()[["sysname"]] == "Windows") {
shell(paste("cd", path, "&&", "git init"))
Expand Down
4 changes: 2 additions & 2 deletions R/shiny_app_template.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ shiny_app_template <- function(app_name = "WRITE APP NAME HERE",
"navbarPage(",
' id = "intabset", # id used for jumping between tabs',
" title = div(",
' tags$a(img(src = "phs-logo.png", height = 40,',
' tags$a(img(src = "phs-logo-white.png", height = 40,',
' alt ="Go to Public Health Scotland (external site)"),',
' href = "https://www.publichealthscotland.scot/",',
' target = "_blank"), # PHS logo links to PHS website',
' style = "position: relative; top: -5px;"),',
' style = "position: relative; top: -10px;"),',
paste0(" windowTitle = ", '"', app_name, '"', ",", "# Title for browser tab"),
' header = tags$head(includeCSS("www/styles.css"), # CSS stylesheet',
' tags$link(rel = "shortcut icon", href = "favicon_phs.ico") # Icon for browser tab',
Expand Down
Binary file added inst/images/phs-logo-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions inst/rstudio/templates/project/phsshinyapp.dcf
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ Widget: TextInput
Label: App Name
Default: WRITE APP NAME HERE

Parameter: phs_white_logo
Widget: CheckboxInput
Label: Use PHS White Logo
Default: On

Parameter: git
Widget: CheckboxInput
Label: Initialise with Git
Expand Down
2 changes: 1 addition & 1 deletion inst/text/shiny/shiny_css.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}

.navbar-default {color: var(--white); background-color: var(--phs-purple); }
.navbar-default .navbar-brand, .navbar-default:hover .navbar-brand:hover, .navbar-brand {color: var(--phs-purple); background-color: var(--white)}
.navbar-default .navbar-brand, .navbar-default:hover .navbar-brand:hover, .navbar-brand {color: var(--phs-purple); background-color: var(--phs-purple)}
.navbar-default .navbar-nav > li > a {color: var(--white);}
.navbar-default .navbar-nav > .active > a, .navbar-default .navbar-nav > .active > a:focus, .navbar-default .navbar-nav > .active > a:hover {
color: var(--white);
Expand Down
3 changes: 3 additions & 0 deletions man/phsshinyapp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a2bdf1c

Please sign in to comment.