Learn R Programming

shinyjs (version 0.0.7.0)

colourInput: Create a colour input control

Description

Create an input control to select a colour.

Usage

colourInput(inputId, label, value = "white", showColour = c("both", "text",
  "background"), allowTransparent = FALSE, transparentText)

Arguments

inputId
The input slot that will be used to access the value.
label
Display label for the control, or `NULL for no label.
value
Initial value (can be a colour name or HEX code)
showColour
Whether to show the chosen colour as text inside the input, as the background colour of the input, or both (default).
allowTransparent
If TRUE, then add a checkbox that allows the user to select the transparent colour.
transparentText
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; w

Details

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, but the value returned from the input will be an uppercase HEX value in both cases. 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 "transpanrent", otherwise the return value is always a HEX value.

See Also

updateColourInput

Examples

Run this code
if (interactive()) {
  shiny::shinyApp(
    ui = shiny::fluidPage(
      shiny::div("Selected colour:",
                 shiny::textOutput("value", inline = TRUE)),
      colourInput("col", "Choose colour", "red"),
      shiny::h3("Update colour input"),
      shiny::textInput("text", "New colour: (colour name or HEX value)"),
      shiny::selectInput("showColour", "Show colour",
        c("both", "text", "background")),
      shiny::checkboxInput("allowTransparent", "Allow transparent", FALSE),
      shiny::actionButton("btn", "Update")
    ),
    server = function(input, output, session) {
      shiny::observeEvent(input$btn, {
        updateColourInput(session, "col",
          value = input$text, showColour = input$showColour,
          allowTransparent = input$allowTransparent)
      })
      output$value <- shiny::renderText(input$col)
    }
  )
}

Run the code above in your browser using DataLab