
Last chance! 50% off unlimited learning
Sale ends in
colourInput(inputId, label, value = "white", showColour = c("both", "text",
"background"), palette = c("square", "limited"), allowedCols,
allowTransparent = FALSE, transparentText)
input
slot that will be used to access the value.NULL
for no label.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 cpalette == "limited"
. The limited
palette
uses a default list of 40 colours if allowedCols
is not defined.TRUE
, then add a checkbox that allows the
user to select the transparent
colour.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; wcolourInput
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.updateColourInput
if (interactive()) {
shiny::shinyApp(
ui = shiny::fluidPage(
shiny::strong("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::selectInput("palette", "Colour palette",
c("square", "limited")),
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,
palette = input$palette)
})
output$value <- shiny::renderText(input$col)
}
)
}
Run the code above in your browser using DataLab