Change the value of a colour input on the client.
updateColourInput(
session,
inputId,
label = NULL,
value = NULL,
showColour = NULL,
palette = NULL,
allowedCols = NULL,
allowTransparent = NULL,
returnName = NULL,
closeOnClick = NULL
)The session object passed to function given to shinyServer.
The id of the colour input object.
The label to set for the input object.
The value to set for the input object.
Whether to show the chosen colour as text inside the input, as the background colour of the input, or both (default).
The type of colour palette to allow the user to select colours
from. 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 choose from.
A list of colours that the user can choose from. Only
applicable when palette == "limited". The limited palette
uses a default list of 40 colours if allowedCols is not defined. If
the colour specified in value is not in the list, the default colour
will revert to black.
If TRUE, enables a slider to choose an alpha
(transparency) value for the colour. When a colour with opacity is
chosen, the return value is an 8-digit HEX code.
If TRUE, then return the name of an R colour instead
of a HEX value when possible.
If TRUE, then the colour selection panel will close
immediately after selecting a colour.
The update function sends a message to the client, telling it to change
the settings of a colour input object.
This function works similarly to the update functions provided by shiny.
Any argument with NULL values will be ignored.
See https://daattali.com/shiny/colourInput/ for a live demo.
if (interactive()) {
library(shiny)
shinyApp(
ui = fluidPage(
div("Selected colour:", textOutput("value", inline = TRUE)),
colourInput("col", "Choose colour", "red"),
h3("Update colour input"),
textInput("text", "New colour: (colour name or HEX value)"),
selectInput("showColour", "Show colour",
c("both", "text", "background")),
checkboxInput("allowTransparent", "Allow transparent", FALSE),
checkboxInput("returnName", "Return R colour name", FALSE),
actionButton("btn", "Update")
),
server = function(input, output, session) {
observeEvent(input$btn, {
updateColourInput(session, "col",
value = input$text, showColour = input$showColour,
allowTransparent = input$allowTransparent,
returnName = input$returnName)
})
output$value <- renderText(input$col)
}
)
}