I am trying to show users that the numeric value they enter into an input field is recognized as a currency, and have found the autonumericInput() function from shinyWidgets as easy way to accomplish this. However, I would also like to alert users when they have left this field blank using shinyFeedback. These two packages appear to have a conflict or I am not understanding the logic I should use to represent a blank autonumericInput, which is potentially different from the standard numericInput. Below please find a minimal reprex demonstrating the issue. To solve for this issue, I either need to find a way to get shinyFeedback to work with autonumericInput or I need to find a way to format input values in numericInput as currency, which does not seem to be possible. Thanks!
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",
currencySymbol = "$"
),
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)