Learn R Programming

shinyjs (version 0.0.7.0)

updateColourInput: Change the value of a colour input

Description

Change the value of a colour input on the client.

Usage

updateColourInput(session, inputId, label = NULL, value = NULL,
  showColour = NULL, allowTransparent = NULL, transparentText = NULL)

Arguments

session
The session object passed to function given to shinyServer.
inputId
The id of the colour input object.
label
The label to set for the input object.
value
The value to set for the input object.
showColour
Whether to shoW the chosen colour via text, background, or both.
allowTransparent
If TRUE, then add a checkbox that allows the user to select the transparent colour.
transparentText
The text to show beside the transparency checkbox when allowTransparent is TRUE

Details

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 Also

colourInput

Examples

Run this code
if (interactive()) {
  shiny::shinyApp(
    ui = shiny::fluidPage(
      shiny::div("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::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)
      })
      output$value <- shiny::renderText(input$col)
    }
  )
}

Run the code above in your browser using DataLab