File: colourInput.Rd

package info (click to toggle)
r-cran-colourpicker 1.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,548 kB
  • sloc: javascript: 1,490; makefile: 13; sh: 3
file content (120 lines) | stat: -rw-r--r-- 4,303 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/colourInput.R
\name{colourInput}
\alias{colourInput}
\title{Create a colour input control}
\usage{
colourInput(
  inputId,
  label,
  value = "white",
  showColour = c("both", "text", "background"),
  palette = c("square", "limited"),
  allowedCols = NULL,
  allowTransparent = FALSE,
  returnName = FALSE,
  closeOnClick = FALSE
)
}
\arguments{
\item{inputId}{The \code{input} slot that will be used to access the value.}

\item{label}{Display label for the control, or `\code{NULL} for no label.}

\item{value}{Initial value (can be a colour name or HEX code)}

\item{showColour}{Whether to show the chosen colour as text inside the input,
as the background colour of the input, or both (default).}

\item{palette}{The type of colour palette to allow the user to select colours
from. \code{square} (default) shows a square colour palette that allows the
user to choose any colour, while \code{limited} only gives the user a
predefined list of colours to choose from.}

\item{allowedCols}{A list of colours that the user can choose from. Only
applicable when \code{palette == "limited"}. The \code{limited} palette
uses a default list of 40 colours if \code{allowedCols} is not defined. If
the colour specified in \code{value} is not in the list, the default colour
will revert to black.}

\item{allowTransparent}{If \code{TRUE}, enables a slider to choose an alpha
(transparency) value for the colour. When a colour with opacity is
chosen, the return value is an 8-digit HEX code.}

\item{returnName}{If \code{TRUE}, then return the name of an R colour instead
of a HEX value when possible.}

\item{closeOnClick}{If \code{TRUE}, then the colour selection panel will close
immediately after selecting a colour.}
}
\description{
Create an input control to select a colour.
}
\details{
A colour input allows users to select a colour by clicking on the desired
colour, or by entering a valid colour in the input box. Colours can be
specified as either names ("blue"), HEX codes ("#0000FF"), RGB codes
("rgb(0, 0, 255)"), or HSL codes ("hsl(240, 100, 50)"). Use
\code{allowTransparent = TRUE} to allow selecting semi-transparent colours.
The return value is a HEX value by default, but you can use the
\code{returnName = TRUE} parameter to get an R colour name instead
(only when an R colour exists for the selected colour).

When \code{allowTransparent = TRUE}, the user can type into the input field
any RGBA value, HSLA value, or 8-digit HEX with alpha channel You can also use
any of these values as the \code{value} argument as the initial value of the
input.
}
\note{
See \href{https://daattali.com/shiny/colourInput/}{https://daattali.com/shiny/colourInput/}
for a live demo.
}
\examples{
if (interactive()) {
  # Example 1
  library(shiny)
  shinyApp(
    ui = fluidPage(
      colourInput("col", "Choose colour", "red"),
      plotOutput("plot")
    ),
    server = function(input, output, session) {
      output$plot <- renderPlot({
        plot(1:10, col = input$col)
      })
    }
  )

  # Example 2
  library(shiny)
  shinyApp(
    ui = fluidPage(
      strong("Selected colour:", textOutput("value", inline = TRUE)),
      colourInput("col", "Choose colour", "red"),
      h3("Update colour input"),
      textInput("text", "New colour: (colour name or HEX value)"),
      selectInput("showColour", "Show colour",
        c("both", "text", "background")),
      selectInput("palette", "Colour palette",
        c("square", "limited")),
      checkboxInput("allowTransparent", "Allow transparent", FALSE),
      checkboxInput("returnName", "Return R colour name", FALSE),
      actionButton("btn", "Update")
    ),
    server = function(input, output, session) {
      observeEvent(input$btn, {
        updateColourInput(session, "col",
          value = input$text, showColour = input$showColour,
          allowTransparent = input$allowTransparent,
          palette = input$palette,
          returnName = input$returnName)
      })
      output$value <- renderText(input$col)
    }
  )
}
}
\seealso{
\code{\link[colourpicker]{updateColourInput}}
\code{\link[colourpicker]{colourPicker}}
}