Like renderTree, but expr may also return a promise
(see the promises package) of the tree, for a tree that is slow to
build: with future, it is built in another process and the app stays
responsive in the meantime. The tree is sent once the promise resolves; if
it is rejected, the error is shown in place of the tree. An expression that
returns a tree straight away works as it does in renderTree.
Usage
renderTreeAsync(expr, env = parent.frame(), quoted = FALSE)Arguments
- expr
An expression that returns a nested list or JSON, as for
renderTree, or a promise of one.- env
The environment in which
exprshould be evaluated.- quoted
Is
expra quoted expression (withquote())? This is useful if you want to save an expression in a variable.
Value
A render function, to assign to output$<id> for a
shinyTree with that id.
Examples
if (interactive() && requireNamespace("future", quietly = TRUE)) {
library(shiny)
library(promises)
library(future)
plan(multisession)
ui <- fluidPage(shinyTree("tree"))
server <- function(input, output, session) {
output$tree <- renderTreeAsync({
future({
Sys.sleep(2) # a tree that is slow to build
list(root = list(leaf = ""))
})
})
}
shinyApp(ui, server)
}
# See also the 16-async example:
if (interactive()) {
shiny::runApp(system.file("examples/16-async", package = "shinyTree"))
}