Search code examples
rshinyshinywidgets

shinyFeedback not working with shinyWidgets' autonumericInput function


I am trying to implement feedback for users of my app using shinyFeedback. I use custom currency formatting of numeric inputs from shinyWidgets. These two do not seem to work together. Below is a reprex showing shinyFeedback working correctly with numericInput, but not working with autonumericInput.

Is there any trick to make these two work together?

undesired behaviour

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

ui <- fluidPage(
  useShinyFeedback(),
  numericInput(
    "numeric_input", "numeric_input",
    value = 1e6, min = -Inf, max = Inf
  ),
  autonumericInput(
    "autonumeric_input", "autonumeric_input",
    value = 1e6, currencySymbol = "€", currencySymbolPlacement = "p", decimalPlaces = 0, digitGroupSeparator = " "
  ),
)

server <- function(input, output, session) {

  observeEvent(input$numeric_input, {
    feedbackWarning("numeric_input", show = input$numeric_input >= 0, text = "Hello numeric_input")
  })
  
  observeEvent(input$autonumeric_input, {
    feedbackWarning("autonumeric_input", show = input$autonumeric_input >= 0, text = "Hello autonumeric_input")
  })

}

shinyApp(ui, server)

Solution

  • This may be a workaround to solve this sort of problem.

    image

    library(shiny)
    library(shinyWidgets)
    library(tidyverse)
    
    ui <- fluidPage(
      
      tags$head(
        tags$style(
          HTML(".shiny-notification {
                 position:fixed;
                 top: calc(1%);
                 left: calc(1%);
                 }
                 "
          )
        )
      ),
      
      br(), br(), br(), br(),
      autonumericInput(
        "autonumeric_input", "autonumeric_input",
        value = 0, minimumValue = 0, maximumValue = 1, currencySymbol = "€", currencySymbolPlacement = "p", decimalPlaces = 0, digitGroupSeparator = " "
      ),
    )
    
    server <- function(input, output, session) {
    
      observeEvent(input$autonumeric_input, {
        
        showNotification(duration = 1.5, "Notification", type = "warning")
        
      })
    
    }
    
    shinyApp(ui, server)