## ----setup, include = FALSE--------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.align = "center", fig.width = 7, fig.height = 4.5, dpi = 96, out.width = "100%" ) library(NDPalette) has_ggplot2 <- requireNamespace("ggplot2", quietly = TRUE) if (has_ggplot2) { library(ggplot2) theme_set(theme_minimal(base_size = 12)) } knitr::opts_chunk$set(eval = has_ggplot2) ## ----run, eval = FALSE-------------------------------------------------------- # shiny::runApp(system.file("examples", "nd-shiny-app", package = "NDPalette")) ## ----app-source, echo = FALSE, comment = "", eval = TRUE---------------------- cat(readLines(system.file("examples", "nd-shiny-app", "app.R", package = "NDPalette")), sep = "\n") ## ----app-extras, eval = FALSE------------------------------------------------- # # 1. The three backgrounds (white, plus two soft informal tints): # bg_choices <- c("White" = "#ffffff", # "Soft white" = nd_informal_tints[["soft_white"]], # "Soft yellow" = nd_informal_tints[["soft_yellow_light"]]) # # # 2. Re-theme live when the choice changes: # observeEvent(input$bg, session$setCurrentTheme(nd_theme(bg_choices[[input$bg]]))) # # # 3. A copy-to-clipboard button for the shown code (plain HTML + JS): # tags$button("Copy", class = "btn btn-sm btn-primary", # onclick = "navigator.clipboard.writeText( # document.getElementById('themecode').innerText)") ## ----bg-compare, eval = TRUE, echo = FALSE, fig.height = 2.2, fig.width = 9---- bgs <- c("White" = "#ffffff", "Soft white" = unname(nd_informal_tints[["soft_white"]]), "Soft yellow" = unname(nd_informal_tints[["soft_yellow_light"]])) op <- par(mfrow = c(1, 3), mar = c(0, 0, 1.8, 0)) for (nm in names(bgs)) { plot.new(); plot.window(c(0, 1), c(0, 1)) rect(0, 0, 1, 1, col = bgs[[nm]], border = "grey80") title(sprintf("%s (%s)", nm, bgs[[nm]]), col.main = nd_color("navy")) text(0.5, 0.56, "Notre Dame", col = nd_color("navy"), font = 2, cex = 1.6) text(0.5, 0.40, "navy on a soft page", col = nd_color("navy")) } par(op) ## ----theme-code, eval = FALSE------------------------------------------------- # nd_theme <- bslib::bs_theme( # version = 5, # bg = nd_informal_tints[["soft_yellow"]], # soft, non-white page # fg = nd_color("navy"), # primary = nd_color("navy"), # secondary = nd_color("bright_gold") # ) ## ----fig-demo, fig.height = 4------------------------------------------------- set.seed(113) df <- data.frame(x = rnorm(120), y = rnorm(120), group = factor(rep(LETTERS[1:3], length.out = 120))) ggplot(df, aes(x, y, color = group)) + geom_point(size = 2, alpha = 0.85) + scale_color_nd(palette = "nd_cvd") + labs(color = NULL) ## ----includecss, eval = FALSE------------------------------------------------- # ui <- fluidPage( # shiny::includeCSS(nd_css_path()), # titlePanel("My Notre Dame app") # # ... # ) ## ----nd, eval = TRUE, fig.height = 1.8, fig.width = 9------------------------- pal <- nd_palette() named <- nd_colors[match(pal, nd_colors$hex), ] show_palette(pal, labels = named$name) ## ----cvd, eval = TRUE, fig.height = 1.8, fig.width = 9------------------------ show_palette(nd_palette(palette = "nd_cvd")) ## ----former, eval = TRUE, fig.height = 1.6, fig.width = 8--------------------- show_palette(nd_palette(palette = "former")) ## ----tints, eval = TRUE------------------------------------------------------- nd_tints ## ----informal, eval = TRUE---------------------------------------------------- nd_informal_tints ## ----catalog, eval = TRUE----------------------------------------------------- nd_colors ## ----by-name, eval = TRUE----------------------------------------------------- # The two current primaries, and a former color, by name. nd_color("navy", "metallic_gold", "maroon") # A whole role group. nd_color(role = "tint")