input-colors: Picker input to select color(s) or palette

Description Usage Arguments Value Examples

Description

Select menu to view and choose a color or a palette of colors.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
colorPicker(
  inputId,
  label,
  choices,
  selected = NULL,
  textColor = "#000",
  plainColor = FALSE,
  multiple = FALSE,
  pickerOpts = list(),
  width = NULL
)

palettePicker(
  inputId,
  label,
  choices,
  selected = NULL,
  textColor = "#000",
  plainColor = FALSE,
  pickerOpts = 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 values to select from. Values must be valid Hex colors. If elements of the list are named then that name rather than the value is displayed to the user.

selected

The initially selected value (or multiple values if multiple = TRUE). If not specified then defaults to the first value for single-select lists and no values for multiple select lists.

textColor

Color of the text displayed above colors, can be a vector of the same length as choices.

plainColor

Color the full space of the choice menu.

multiple

Is selection of multiple items allowed?

pickerOpts

Options for pickerInput.

width

The width of the input : 'auto', 'fit', '100px', '75%'.

Value

A select control that can be added to a UI definition.

Examples

  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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# colorPicker -------------------------------------------------------------

if (interactive()) {
  
  library(shiny)
  library(esquisse)
  library(scales)
  
  
  ui <- fluidPage(
    tags$h2("colorPicker examples"),
    fluidRow(
      column(
        width = 3,
        colorPicker(
          inputId = "col1",
          label = "With a vector of colors",
          choices = brewer_pal(palette = "Dark2")(8)
        ),
        verbatimTextOutput("res1")
      ),
      column(
        width = 3,
        colorPicker(
          inputId = "col2",
          label = "Change text color",
          choices = brewer_pal(palette = "Blues")(8), 
          textColor = c("black", "black", "black", "white",
                        "white", "white", "white", "white")
        ),
        verbatimTextOutput("res2")
      ),
      column(
        width = 3,
        colorPicker(
          inputId = "col3",
          label = "With a list of vector of colors",
          choices = list(
            "Blues" = brewer_pal(palette = "Blues")(8),
            "Reds" = brewer_pal(palette = "Reds")(8),
            "Greens" = brewer_pal(palette = "Greens")(8)
          )
        ),
        verbatimTextOutput("res3")
      ),
      column(
        width = 3,
        colorPicker(
          inputId = "col4",
          label = "Plain color",
          choices = brewer_pal(palette = "Paired")(8), 
          plainColor = TRUE, 
          multiple = TRUE, 
          pickerOpts = list(`selected-text-format`= "count > 3")
        ),
        verbatimTextOutput("res4")
      )
    )
  )
  
  server <- function(input, output, session) {
    
    output$res1 <- renderPrint(input$col1)
    output$res2 <- renderPrint(input$col2)
    output$res3 <- renderPrint(input$col3)
    output$res4 <- renderPrint(input$col4)
    
  }
  
  shinyApp(ui, server)
  
}

# palettePicker -----------------------------------------------------------

if (interactive()) {
  
  library(shiny)
  library(esquisse)
  library(scales)
  
  ui <- fluidPage(
    tags$h2("pickerColor examples"),
    
    fluidRow(
      column(
        width = 4,
        palettePicker(
          inputId = "pal1", 
          label = "Select a palette", 
          choices = list(
            "Blues" = brewer_pal(palette = "Blues")(8),
            "Reds" = brewer_pal(palette = "Reds")(8)
          )
        ),
        verbatimTextOutput("res1")
      ),
      column(
        width = 4,
        palettePicker(
          inputId = "pal2", 
          label = "With a list of palette", 
          choices = list(
            "Viridis" = list(
              "viridis" = viridis_pal(option = "viridis")(10),
              "magma" = viridis_pal(option = "magma")(10),
              "inferno" = viridis_pal(option = "inferno")(10),
              "plasma" = viridis_pal(option = "plasma")(10),
              "cividis" = viridis_pal(option = "cividis")(10)
            ),
            "Brewer" = list(
              "Blues" = brewer_pal(palette = "Blues")(8),
              "Reds" = brewer_pal(palette = "Reds")(8),
              "Paired" = brewer_pal(palette = "Paired")(8),
              "Set1" = brewer_pal(palette = "Set1")(8)
            )
          ), 
          textColor = c(
            rep("white", 5), rep("black", 4) 
          )
        ),
        verbatimTextOutput("res2")
      ),
      column(
        width = 4,
        palettePicker(
          inputId = "pal3", 
          label = "With plain colors", 
          choices = list(
            "BrBG" = brewer_pal(palette = "BrBG")(8), 
            "PiYG" = brewer_pal(palette = "PiYG")(8), 
            "PRGn" = brewer_pal(palette = "PRGn")(8), 
            "PuOr" = brewer_pal(palette = "PuOr")(8), 
            "RdBu" = brewer_pal(palette = "RdBu")(8), 
            "RdGy" = brewer_pal(palette = "RdGy")(8), 
            "RdYlBu" = brewer_pal(palette = "RdYlBu")(8), 
            "RdYlGn" = brewer_pal(palette = "RdYlGn")(8), 
            "Spectral" = brewer_pal(palette = "Spectral")(8)
          ), 
          plainColor = TRUE, 
          textColor = "white"
        ),
        verbatimTextOutput("res3")
      )
    )
  )
  
  server <- function(input, output, session) {
    
    output$res1 <- renderPrint(input$pal1)
    output$res2 <- renderPrint(input$pal2)
    output$res3 <- renderPrint(input$pal3)
    
  }
  
  shinyApp(ui, server)
  
}

dtsonipmph/esquisse documentation built on Sept. 14, 2020, 9:34 a.m.