Learn R Programming

shinyWidgets (version 0.4.3)

spectrumInput: Palette Color Picker with Spectrum Library

Description

A widget to select a color within palettes, and with more options if needed.

Usage

spectrumInput(inputId, label, choices = NULL, selected = NULL,
  flat = FALSE, options = list(), width = NULL)

Arguments

inputId

The input slot that will be used to access the value.

label

Display label for the control, or NULL for no label.

choices

List of colors to display in the menu.

selected

The initially selected value.

flat

Display the menu inline.

options

Additional options to pass to spectrum, possible values are described here : https://bgrins.github.io/spectrum/#options.

width

The width of the input, e.g. 400px, or 100%.

Value

The selected color in Hex format server-side

Examples

Run this code
# NOT RUN {
if (interactive()) {

library("shiny")
library("shinyWidgets")
library("RColorBrewer")

ui <- fluidPage(
  tags$h1("Spectrum color picker"),

  br(),

  spectrumInput(
    inputId = "myColor",
    label = "Pick a color:",
    choices = list(
      list('black', 'white', 'blanchedalmond', 'steelblue', 'forestgreen'),
      as.list(brewer.pal(n = 9, name = "Blues")),
      as.list(brewer.pal(n = 9, name = "Greens")),
      as.list(brewer.pal(n = 11, name = "Spectral")),
      as.list(brewer.pal(n = 8, name = "Dark2"))
    ),
    options = list(`toggle-palette-more-text` = "Show more")
  ),
  verbatimTextOutput(outputId = "res")

)

server <- function(input, output, session) {

  output$res <- renderPrint(input$myColor)

}

shinyApp(ui, server)

}

# }

Run the code above in your browser using DataLab