How to make a value inside of reactive() change, depending on an observeEvent() inside of that reactive()

Viewed 4539

Here is the snippet, the question is: how do i make it so observeEvent() inside a reactive() will change the a value?

edit: the real question is, "is it possible without reactiveValues()?

ui <- fluidPage(
  actionButton("btn_change", "Change Values"),
  actionButton("btn_print","Print values")
)

server <- function(input, output) {
    a <- 1
    data <- reactive({
      observeEvent(input$btn_change, {
        a <- a + 1
      })
      a
    })

  observeEvent(input$btn_print, {
    print(paste("data = ", data()))
  })
}

shinyApp(ui, server)
1 Answers
Related