我想知道如何显示经过多次修改的变量的值,我尝试使用future方法,但它不起作用。
library(shiny)
# library(ipc)
# library(future)
# library(promises)
# plan(multiprocess)
ui <- fluidPage(
textOutput("t")
)
server <- function(input, output, session) {
status <- reactiveVal({NULL})
observe({
status("beginning")
# a function that takes a lot of time
Sys.sleep(2)
status("End")
})
# observe({
# future({
# queue$producer$fireAssignReactive("var", 0)
# Sys.sleep(2)
# queue$producer$fireAssignReactive("var", 1)
# }); NULL
# })
output$t <- renderText(status())
}
shinyApp(ui, server)
答案 0 :(得分:0)
此代码每两秒将“ var”增加1。 这就是你想要的吗?
library(shiny)
# library(ipc)
# library(future)
# library(promises)
# plan(multiprocess)
ui <- fluidPage(
textOutput("t")
)
server <- function(input, output, session) {
var <- reactiveVal(-1)
# observer that invalidates every second. If timer is active, decrease by one.
observe({
invalidateLater(2000, session)
isolate({
var(var()+1)
})
})
output$t <- renderText(var())
}
shinyApp(ui, server)