【问题标题】:In R/Shiny, is there a way to create a progress bar for renderTree在 R/Shiny 中,有没有办法为 renderTree 创建进度条
【发布时间】:2021-09-23 15:20:17
【问题描述】:

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

【问题讨论】:

    标签: r shiny rendering shinytree


    【解决方案1】:

    您可以使用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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-07-31
      • 1970-01-01
      • 2022-01-26
      • 1970-01-01
      • 2023-04-10
      • 2019-10-20
      • 2021-03-20
      相关资源
      最近更新 更多