ActionButton returns to zero, but when clicked again, the number of clicks does not reset

ActionButton returns to zero, but when clicked again, the number of clicks does not reset. I'm using the Shiny.onInputChange function. Any ideas?

library(shiny)

ui <- fluidPage(
  
  tags$script("Shiny.addCustomMessageHandler('resetInputValue', function(variableName){
                Shiny.onInputChange(variableName, 0);});"),
  
  titlePanel("ActionButton doesen't return to zero"),
  
  sidebarLayout(
    sidebarPanel(
      splitLayout(
        actionButton(inputId = "button",
                     label = "Button",
                     icon = icon("plus")),
        actionButton(inputId = "reset",
                     label = "Reset",
                     icon = icon("power-off")) 
      )
    ),
    
    mainPanel(
      textOutput(outputId = "ButtonValue")
    )
  )
)

server <- function(input, output, session) {
   
  output$ButtonValue <- renderText({
    paste("Button current value:", input$button, sep = " ")
  })
  
  observeEvent(input$reset, {
    session$sendCustomMessage(type = 'resetInputValue', message = "button")
  })
   
}

shinyApp(ui = ui, server = server)
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.