我不明白为什么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)
})
}
)
observeEvent
中的current_row = current_row + 1
实际上并没有更新全局环境中的current_row
值。你需要<<-
.但是,在shiny
中使用它是非常不明智的。考虑问一个关于你到底需要什么的单独问题,以便人们可以为你指出正确的方向。
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)
})
}
)