Here is a code solution:
library(shiny)
library(ipc)
library(future)
plan(multiprocess)
calc <- function(i) {
Sys.sleep(i * 2)
}
ui <- shinyUI(fluidPage(
titlePanel("Test update computation status flag"),
sidebarLayout(
sidebarPanel(
fluidRow(
column(8,
"Status:",
textOutput("status1")
),
column(4,
"Box1"
)
),
hr(),
fluidRow(
column(8,
"Status:",
textOutput("status2")
),
column(4,
"Box2"
)
),
hr(),
fluidRow(align = "center",
actionButton("startButton", "START")
)
),
mainPanel()
)
))
server <- shinyServer(function(input, output, session) {
queue <- shinyQueue()
queue$consumer$start(100) # Execute signals every 100 milliseconds
stat1 <- reactiveVal(NULL)
stat2 <- reactiveVal(NULL)
observeEvent(input$startButton, {
future({
for(i in 1:2) {
queue$producer$fireAssignReactive(paste0("stat",i), "queue")
}
for(i in 1:2) {
queue$producer$fireAssignReactive(paste0("stat",i), "running")
calc(i)
queue$producer$fireAssignReactive(paste0("stat",i), "done")
}
})
#Return something other than the future so we don't block the UI
NULL
})
output$status1 <- renderText(stat1())
output$status2 <- renderText(stat2())
})
shinyApp(ui = ui, server = server)