I am trying to use futures to have a "loading" icon appear. This is the code I have
library(shiny)
library(promises)
library(future)
plan(multiprocess)
disksUI <- function(id) {
ns <- NS(id)
fluidRow(
box(
uiOutput(ns("loading")),
dataTableOutput(ns("filelist")),
width=12
)
)
}
disksServer <- function(input, output, session) {
state <- reactiveValues(onLoading=FALSE)
observe({
if (state$onLoading) {
output$loading <- renderUI("Loading")
} else {
output$loading <- renderUI("Done")
}
})
filelist <- reactive(
{
state$onLoading <- TRUE
future({
Sys.sleep(3)
state$onLoading <- FALSE
}
)
}
)
output$filelist <- renderDataTable({
filelist()
})
}
However, the result is not what I expect. What I expect is
- the string Loading appears immediately
- after three seconds, the string Loading is replaced with Done
What happens is
- Nothing is written for three seconds.
- After three seconds, the Loading string appears.