0

我正在为 R/Shiny 应用程序使用 shinyTree 包,并且正在渲染一些相当大的树。我不知道为什么需要这么长时间,但渲染树需要几分钟。有什么办法可以让 renderTree 的进度条,让用户至少知道发生了什么事吗?或者,有没有办法在渲染完成时获取某种事件,以便我可以显示一条消息“正在渲染,请稍候”,然后在渲染完成时将其删除?

4

1 回答 1

0

您可以使用shinycssloaders显示加载动画,直到渲染完成。

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)
于 2021-09-23T20:20:18.347 回答