R 闪亮的应用程序没有';t如我所期望的那样增加变量

R 闪亮的应用程序没有';t如我所期望的那样增加变量,r,shiny,R,Shiny,我无法理解为什么在按下“上一步”和“下一步”按钮之间,当前_行变量被重置为其初始值 泰 observeEvent中的current\u row=current\u row+1实际上不会在全局环境中更新current\u row值。您需要 current_row = 0 shinyApp( ui = fluidPage( actionButton("next_button", "next"), actionButton("previous_button", "previous

我无法理解为什么在按下“上一步”和“下一步”按钮之间,当前_行变量被重置为其初始值


observeEvent
中的
current\u row=current\u row+1
实际上不会在全局环境中更新
current\u row
值。您需要

current_row = 0

shinyApp(
  ui = fluidPage(
    actionButton("next_button", "next"),
    actionButton("previous_button", "previous")
  ),
  server = function(input, output, session) {

    observeEvent(input$next_button, 
                 {
                   current_row = current_row + 1 
                   print (current_row)
                 }) 

    observeEvent(input$previous_button, 
                 {
                   current_row = current_row - 1 
                   print (current_row)
                 }) 
  }
)
current_row = 0

shinyApp(
  ui = fluidPage(
    actionButton("next_button", "next"),
    actionButton("previous_button", "previous")
  ),
  server = function(input, output, session) {

    observeEvent(input$next_button, 
                 {
                   current_row <<- current_row + 1 
                   print (current_row)
                 }) 

    observeEvent(input$previous_button, 
                 {
                   current_row <<- current_row - 1 
                   print (current_row)
                 }) 
  }
)