daattali / colourpicker

🎨 A colour picker tool for Shiny and for selecting colours in plots (in R)
https://daattali.com/shiny/colourInput/
Other
217 stars 28 forks source link

updateColourInput #7

Closed bklingen closed 7 years ago

bklingen commented 7 years ago

Somehow, using updateColourInput, I lose the ability to access the hex code in the box. The app below demonstrates. First, I can access the value in the colorbox and potentially paste a different value in. Then, clicking the checkbox to not show the hex code hides it (as desired), but unchecking the box to display it again all of a sudden makes the displayed hex code not accessible. I.e., I can't click into the box to change it (or past in another value).

library(shiny)
library(colourpicker)
ui <- fluidPage(
  colourInput("mycol", "Pick Color", value="#FFED6F", showColour="both"),
  checkboxInput("hex", "Show color value (in hex form)", TRUE)
)

server <- function(input, output, session) {
  observeEvent(input$hex, {
    if (input$hex) type <- "both" else type <- "background"
    updateColourInput(session, "mycol", showColour=type)
    }, ignoreInit=TRUE  
  )
}

shinyApp(ui = ui, server = server)
daattali commented 7 years ago

Thank you for the report, you're right. I never noticed that before. After looking into it for 30 seconds, it looks like it's because the input still has a readonly attribute on it, which gets added on from the javascript library here

So the fix would probably have to be done in the JS library, not in the shiny code. I'll try to tackle it when I can

daattali commented 7 years ago

fixed

bklingen commented 7 years ago

Thanks! Works great!