This means that you can start with a basic colour input such as colourInput("col", "Select colour") and completely redesign it with Any parameter that can be used in colourInput can be used in updateColourInput. Here is an image of the default limited colour palette.Īs with all other Shiny inputs, colourInput can be updated with the updateColourInput function. By default, the limited palette will contain 40 common colours, but you can supply your own list of colours using the allowedCols parameter. If you want to only allow the user to select a colour from a specific list of colours, rather than any possible HEX colour, you can use the palette = "limited" parameter. Here is what a colour input with each of the possible values for showColour looks like If that’s too much for you, you can customize the input with the showColour parameter to either only show the text or only show the background colour. How the chosen colour is shown inside the inputīy default, the colour input’s background will match the selected colour and the text inside the input field will be the colour’s HEX value.
This is what a colour input with transparency enabled looks like Note that even if you change the checkbox text, the return value will still be transparent since that’s the actual colour name in R. For example, it might be more clear to a user to use the word “None” instead of “Transparent”. When the checkbox is unchecked, the value of the input will be the last selected colour prior to selecting “transparent”.īy default, the text of the checkbox reads “Transparent”, but you can change that with the transparentText parameter. This is the only case when the value returned from a colourInput is not a HEX value. If the user checks the checkbox for “transparent”, then the colour input is grayed out and the returned value of the input is transparent. When this feature is turned on, a checkbox appears inside the input box. By default, only real colours can be selected, so you need to use the allowTransparent = TRUE parameter. Since most functions in R that accept colours can also accept the value “transparent”, colourInput has an option to allow selecting the “transparent” colour. The default value at initialization is white (#FFFFFF). The return value from a colourInput is an uppercase HEX colour, so in the previous example the value of input$col would be #FF0000 (#FF0000 is the HEX value of the colour red). You can add a simple colour input to your Shiny app with colourInput("col", "Select colour", value = "red"). It was implemented to very closely mimic all other Shiny inputs so that using it will feel very familiar. Using colourInput is extremely trivial if you’ve used Shiny, and it’s as easy to use as any other input control. Features of colourInput() Simple and familiar This may not be terribly useful right now since you can use the more powerful colourInput in Shiny apps and Rmarkdown documents, but it may come in handy if you need a widget. The colour picker input is also available as an ‘htmlwidgets’ widget using the colourWidget() function. You can also watch a short GIF of it an action. Here is a screenshot of the colour picker addin (you can either access this tool using the Addins menu or with colourPicker()). This can be useful if, for example, you want to pick some colours for a plot and you want an easy way to visualize and select a few colours. To select colours to use in your R code: colourPicker()Ĭolourpicker also provides an RStudio addin that can be used to easily select colours and save them as a variable in R. Plot(rnorm(50), bg = input$col, col = input$col, pch = 21)
Click here to see the colour picker addin that lets you select colours interactively.Interactive demo of the colour picker input available for Shiny apps. Most of the functionality has existed in the shinyjs package for the past year and this package is simply a way to graduate all the colour picker functions into their own package. The new colourpicker package gives you a colour picker widget that can be used in different contexts in R. Have you ever wanted to allow your users to select colours in your Shiny apps? Have you ever wanted to select a few colours to use in your R code, but found it tedious to search for the right colours? If you answered yes to any of those questions, or if you’re just curious, then colourpicker is the package for you!