daattali / colourpicker

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

Display empty value in colourPicker() #56

Closed DzmitryGB closed 1 year ago

DzmitryGB commented 1 year ago

Thank you for the great package!

Would it be possible to display empty value as checkered transparent box? It shows correctly in the palette, but not in the main input box (example below).

library(shiny)
library(colourpicker)
shinyApp(
  fluidPage(
    inputPanel(
        colourInput(
            "colour", NULL, value = "", showColour = "background", palette = "limited",
            allowedCols = c("", "black", "grey")
        )
    ),
    verbatimTextOutput('textOut')
  ),
  function(input, output, session){
    output$textOut <- renderPrint({
        input$colour
    })
  }
)
daattali commented 1 year ago

Thanks for reporting this. The way you're using the colour input is actually a behaviour that I never intended on allowing! The colour input should always contain a valid colour, and an empty string is not a valid colour. Somehow I never thought of using "" -- if I had thought of it, I would have explicitly disallowed it. But because it's already in use now and I wouldn't want to break existing people's code, I'll just leave it as is.

If you want "no colour" then the correct way to achieve that is using the string "transparent" (or #00000000). I won't be fixing this because I don't want to encourage using "".

DzmitryGB commented 1 year ago

Thank you for your reply. "transparent" value has exactly the behaviour I wanted, thank you!