shinyFeedback icon indicating copy to clipboard operation
shinyFeedback copied to clipboard

Conflict with shinyWidgets autonumericInput

Open Aspirational-Human opened this issue 4 months ago • 0 comments

Hello,

Really like the feedback functions. I can get them to work with several input fields, but not with autonumericInput, which I require for my app to be able to show entered values as currency. The app below demonstrates the issue. I have tried is.null(), is.na() and =="" for the feedback condition, and none seem to work.

library(shiny)
library(bslib)
library(shinyFeedback)
library(shinyWidgets)

ui <- page_fluid(
  useShinyFeedback(),
  
  card(
    card_header("Input Form"),
    textInput("text_input", "Text Input"),
    numericInput("numeric_input", "Numeric Input", value = NA),
    autonumericInput(
      "autonumeric_input",
      "Autonumeric Input",
      value = NULL,
      align = "right",
      decimalPlaces = 2
    ),
    actionButton("submit", "Submit")
  )
  )

server <- function(input, output, session) {
  observeEvent(input$submit, {
    # Check text input
    if (is.null(input$text_input) || input$text_input == "") {
      showFeedbackDanger("text_input", "Please enter some text")
    } else {
      hideFeedback("text_input")
    }
    
    # Check numeric input
    if (is.na(input$numeric_input)) {
      showFeedbackDanger("numeric_input", "Please enter a number")
    } else {
      hideFeedback("numeric_input")
    }
    
    # Check autonumeric input
    if (is.null(input$autonumeric_input) || input$autonumeric_input == "" || is.na(input$autonumeric_input)) {
      showFeedbackDanger("autonumeric_input", "Please enter a number")
    } else {
      hideFeedback("autonumeric_input")
    }
  })
}

shinyApp(ui, server)

Aspirational-Human avatar Oct 22 '24 17:10 Aspirational-Human