HI @yu.cai.tch. Like you, I thought shinyjs
would offer a solution, but according to the documentation for the reset()
function, action buttons are not supported. One way I've handled this before is by introducing a reactiveVal that serves as the button counter (input_button_value in example below). Every time the submit button is clicked, the reactiveVal increases by 1. When the reset button is clicked, the reactiveVal is set to 0. Then, any place in the app I would want to use the counter value of the submit button, I would refer to this reactiveVal.
I reworked the sample app you provided to illustrate this concept below.
library(shiny)
library(shinyjs)
ui <- fluidPage(
actionButton("submit", "Submit"),
actionButton("reset", "reset"),
textOutput("result"),
br(),
textOutput("result2"),
)
server <- function(input, output, session) {
input_button_value <- reactiveVal(0)
observeEvent(input$submit , {
new = input_button_value() + 1
input_button_value(new)
}, ignoreNULL = T)
observeEvent(input$reset, {
input_button_value(0)
} )
output$result <- renderText({
paste("Button clicked! input$submit[[1]] is now:", input$submit[[1]])
})
output$result2 <- renderText({
paste("Button clicked! input_button_value is now:", input_button_value())
})
}
shinyApp(ui, server)