Create a colour input control

Create an input control to select a colour.

colourInput(inputId, label, value = "white", showColour = c("both", "text", "background"), palette = c("square", "limited"), allowedCols, allowTransparent = FALSE, transparentText, returnName = FALSE)
The input slot that will be used to access the value.
Display label for the control, or `NULL for no label.
Initial value (can be a colour name or HEX code)
Whether to show the chosen colour as text inside the input, as the background colour of the input, or both (default).
The type of colour palette to allow the user to select colours from. square (default) shows a square colour palette that allows the user to choose any colour, while limited only gives the user a predefined list of colours to choose from.
A list of colours that the user can choose from. Only applicable when palette == "limited". The limited palette uses a default list of 40 colours if allowedCols is not defined.
If TRUE, then add a checkbox that allows the user to select the transparent colour.
The text to show beside the transparency checkbox when allowTransparent is TRUE. The default value is "Transparent", but you can change it to "None" or any other string. This has no effect on the return value from the input; when the checkbox is checked, the input will always return the string "transparent".
If TRUE, then return the name of an R colour instead of a HEX value when possible.

A colour input allows users to select a colour by clicking on the desired colour, or by entering a valid HEX colour in the input box. The input can be initialized with either a colour name or a HEX value. The return value is a HEX value by default, but you can use the returnName = TRUE parameter to get an R colour name instead (only when an R colour exists for the selected colour).

Since most functions in R that accept colours can also accept the value "transparent", colourInput has an option to allow selecting the "transparent" colour. When the user checks the checkbox for this special colour, the returned value form the input is "transparent".


See for a live demo.

See Also

updateColourInput colourPicker

  • colourInput
if (interactive()) {
    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)
Documentation reproduced from package colourpicker, version 0.3, License: MIT + file LICENSE

Community examples

Looks like there are no examples yet.