Appsilon / shiny.semantic

Shiny support for powerful Fomantic UI library.
http://appsilon.github.io/shiny.semantic
Other
497 stars 96 forks source link

[Bug]: it's not possible to clear dropdown_input #458

Closed TymekDev closed 5 months ago

TymekDev commented 5 months ago

Guidelines

Project Version

No response

Platform and OS Version

No response

Existing Issues

No response

What happened?

The update_dropdown_input function is not capable of resetting a dropdown_input component back to its default value (if it had no initial selection).

Providing selected = "" or selected = character(0) to shiny::updateSelectInput clears the selection (if it had a placeholder provided).

Steps to reproduce

Steps

  1. Create dropdown_input without a default value
  2. Select a value
  3. Try updating the dropdown to clear the selected value

Example

library(shiny)
library(shiny.semantic)

ui <- semanticPage(
  dropdown_input("dropdown", LETTERS[1:5]),
  actionButton("clear", "Clear")
)

server <- function(input, output, session) {
  try_clearing <- function(value) {
    print(value)
    before <- input$dropdown
    update_dropdown_input(session, "dropdown", value = NA)
    after <- input$dropdown
    print(paste("before:", before, "|", "after:", after))
  }

  observeEvent(input$clear, {
    try_clearing(NA)
    try_clearing(NA_character_)
    try_clearing(NULL)
    try_clearing("")
    try_clearing(character(0))
  })
}

shinyApp(ui, server)

Expected behavior

I expected the dropdown_input to be reverted to its original state: no value selected.

Attachments

No response

Screenshots or Videos

No response

Additional Information

No response