Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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(),
  update_on = c("move", "dragstop", "change"),
  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.

update_on

When to update value server-side: "move" (default, each time a new color is selected), "dragstop" (when use user stop dragging cursor), "change" (when the input is closed).

width

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

Value

The selected color in Hex format server-side

Examples

if (interactive()) {

library("shiny")
library("shinyWidgets")
library("scales")

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(palette = "Blues")(9)),
      as.list(brewer_pal(palette = "Greens")(9)),
      as.list(brewer_pal(palette = "Spectral")(11)),
      as.list(brewer_pal(palette = "Dark2")(8))
    ),
    options = list(`toggle-palette-more-text` = "Show more")
  ),
  verbatimTextOutput(outputId = "res")

)

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

  output$res <- renderPrint(input$myColor)

}

shinyApp(ui, server)

}

shinyWidgets

Custom Inputs Widgets for Shiny

v0.6.0
GPL-3
Authors
Victor Perrier [aut, cre, cph], Fanny Meyer [aut], David Granjon [aut], Ian Fellows [ctb] (Methods for mutating vertical tabs & updateMultiInput), Wil Davis [ctb] (numericRangeInput function), Spencer Matthews [ctb] (autoNumeric methods), JavaScript and CSS libraries authors [ctb, cph] (All authors are listed in LICENSE.md)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.