Debian Codegraph @

R/hcl_color_picker.R

raw
1 #' Graphical User Interface to Pick Colors in HCL Space
2 #'
3 #' The app visualizes colors either along the hue-chroma plane for a given luminance value or along the
4 #' luminance-chroma plane for a given hue. Colors can be entered by specifying the hue (H), chroma (C),
5 #' and luminance (L) values via sliders, by entering an RGB hex code, or by clicking on a color in the
6 #' hue-chroma or luminance-chroma plane. It is also possible to select individual colors and add them
7 #' to a palette for comparison and future reference.
8 #'
9 #' \code{choose_color} is a convenience alias for \code{hcl_color_picker} to
10 #' go along with \code{\link{choose_palette}}. Another alias is \code{hclcolorpicker}.
11 #'
12 #' @param shiny.trace logical: used for debugging the shiny interface.
13 #' @author Claus O. Wilke, Reto Stauffer, Achim Zeileis
14 #' @seealso \code{\link{choose_palette}}
15 #' @references Zeileis A, Fisher JC, Hornik K, Ihaka R, McWhite CD, Murrell P, Stauffer R, Wilke CO (2020).
16 #' \dQuote{colorspace: A Toolbox for Manipulating and Assessing Colors and Palettes.}
17 #' \emph{Journal of Statistical Software}, \bold{96}(1), 1--49. \doi{10.18637/jss.v096.i01}
18 #' @keywords misc
19 #'
20 #' @return \code{hclcolorpicker} invisibly returns a vector of colors choosen.
21 #' If no colors have been selected \code{NULL} will be returned.
22 #' @examples
23 #' \dontrun{
24 #' hcl_color_picker()
25 #' }
26 #' @export
27 hcl_color_picker <- function(shiny.trace = FALSE) {
28 # Requirements for shiny application
29 stopifnot(requireNamespace("shiny"), requireNamespace("shinyjs"))
30 appDir <- system.file("hclcolorpicker", package = "colorspace")
31 if (appDir == "")
32 stop("Could not find hclcolorpicker app directory. Try re-installing `colorspace`.", call. = FALSE)
33 # Start shiny
34 options(shiny.trace = shiny.trace)
35 pal <- shiny::runApp(appDir, display.mode = "normal", quiet = TRUE)
36 return(pal)
37 }
38
39
40 #' @rdname hcl_color_picker
41 #' @export
42 choose_color <- function(shiny.trace = FALSE)
43 hcl_color_picker(shiny.trace = shiny.trace)
44
45 #' @rdname hcl_color_picker
46 #' @usage NULL
47 #' @export
48 hclcolorpicker <- function(shiny.trace = FALSE)
49 hcl_color_picker(shiny.trace = shiny.trace)
50