Is it possible to use a selection widget for displaying a colour palette for reactive colour picking? I'd like to let the user pick the colour(s) for the plot that is created by a shiny app.
The shinysky
package has a colorpicker which you can use with shiny
:
require(shinysky)
require(shiny)
runApp(list(
ui = bootstrapPage(
jscolorInput("colorid"),
uiOutput('myPanel'),
plotOutput('plot')
),
server = function(input, output) {
output$myPanel <- renderUI({
mystyle <- ifelse(is.null(input$colorid), "ffffff", input$colorid)
inputPanel(
numericInput('n', 'Number of obs', 100)
, style = paste0("background-color:#", mystyle, ";")
)
})
output$plot <- renderPlot({ hist(runif(input$n)) })
}
))
It is currently not on CRAN so you will need to install it via devtools
details are at https://github.com/AnalytixWare/ShinySky
For anyone coming here looking for a colour picker, the previous answer using shinysky
is outdated (the colour picker from there has been moved to a package that is not under maintenance)
There is another colour picker available for shiny in the shinyjs package.
library(ggplot2)
library(shiny)
library(shinyjs)
runApp(shinyApp(
ui = fluidPage(
colourInput("col", "Select colour", "grey"),
plotOutput("plot")
),
server = function(input, output, session) {
output$plot <- renderPlot({
ggplot(cars, aes(speed, dist)) +
geom_point() +
theme(panel.background = element_rect(fill = input$col))
})
}
))
Disclaimer: I'm the author of this package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With