In R/Shiny, is there a way to create a progress bar for renderTree

127 Views Asked by At

I am using the shinyTree package for an R/Shiny app, and I am rendering some fairly large trees. I don't know why it takes so long, but it is taking several minutes to render the tree. Is there any way to get a progress bar for renderTree, so that the user at least knows that something is happening? Alternatively, is there a way to get some kind of event upon the completion of rendering, so that I can show a message saying "Rendering, please wait" and then remove it when rendering is done?

1

There are 1 best solutions below

0
On

You can use shinycssloaders to show a loading animation until the completion of the rendering.

library(shiny)
library(shinyTree)
library(shinycssloaders)

ui <- fluidPage(
  shinycssloaders::withSpinner(
    shinyTree("tree", contextmenu = TRUE, search = TRUE, unique = TRUE, sort = TRUE)
  )
)

server <- function(input, output, session) {
  output$tree <- renderTree({
    # simulate some complex process
    Sys.sleep(3)
    list(
      root1 = "",
      root2 = list(
        SubListA = list(leaf1 = "", leaf2 = "", leaf3=""),
        SubListB = list(leafA = "", leafB = "")
      ),
      root3 = list(
        SubListA = list(leaf1 = "", leaf2 = "", leaf3=""),
        SubListB = list(leafA = "", leafB = "")
      )
    )
  })
}

shinyApp(ui, server)