dmitry
dmitry

Reputation: 454

How to reset the value of several actionButtons? (shiny package)

I have created some logic where I tried to add several actionButtons, but everything works fine until each button is clicked once. When every button is once clicked all buttons are automatically clicked with the 2nd, 3rd and etc iteration. How do I reset value of actionButton or should I change the whole logic of server side?

observe({
  if (input$actionButton_1 == 0)
    return()
  isolate({
    # logic
  })
 if (input$actionButton_2 == 0)
    return()
  isolate({
    # logic
  })
 ...
})

Upvotes: 3

Views: 2445

Answers (2)

dmitry
dmitry

Reputation: 454

For my purpose I have created observe() for each actionButton and where let's say actionButton outputs are used in other observe() I use global "output <<- f()". Perhaps, this solution is not the best, but it works...

observe({
  if (input$actionButton_1 == 0)
    return()
  isolate({
    # logic
  })
 })
observe({ 
if (input$actionButton_2 == 0)
    return()
  isolate({
    # logic
  })
}) 


...

Upvotes: 1

jlhoward
jlhoward

Reputation: 59425

Well, without ui.R it's very difficult to figure out what's going on, but actionButton(...) is defined as follows in the documentation:

Creates an action button whose value is initially zero, 
and increments by one each time it is pressed.

So all the actionButtons are set to 0 initially. Once you've pressed them all, all of the conditions in your code will test to FALSE (e.g., !=0), and it will appear that all the buttons have been pressed whenever you press any button.

Are you sure you don't want to be using submitButton(...)?

Upvotes: 2

Related Questions