首页 > 解决方案 > 在 R Shiny 中完成 100% 后,是否可以关闭或删除 shinyWidgets 的进程栏?

问题描述

流程完成后如何删除进度条?任何人都可以帮助我。我使用 ShinyWidgets 添加了一个进度条。

界面部分

ui <- fluidPage(
              column(
                width = 7,
                tags$b("Other options"), be(),
    
       progressBar(
              id = "pb2",
              value = 0,
              total = 100,
              title = "",
              display_pct = TRUE,
              status = "custom"
                ),
                tags$style(".progress-bar-custom {background-color: #25c484;}"),
       
                DTOutput("intTable")
              )
            )
            

服务器部分

        server <- function(input, output, session) {
          adae<-read_sas("DATAPATH")## data
        
            for (i in 1:100) {
              updateProgressBar(
                session = session,
                id = "pb2",
                value = i, total = 100
              )
              Sys.sleep(0.1)
            }
        ####==Here I want to close this ProgressBar==######
            output$intTable<-renderDT({adae %>%
                datatable(rownames = FALSE, options = list(dom = 't', pageLength = 200))
            })
        
        }
shinyApp(ui = ui, server = server)

标签: rshinyshinydashboardshinyapps

解决方案


完成后可以使用shinyjs包隐藏它

library(shiny)
library(shinyjs)
library(DT)

ui <- fluidPage(
    useShinyjs(),
    column(
        width = 7,
        tags$b("Other options"),
        div(id = "pb2_vis",
            progressBar(
                id = "pb2",
                value = 0,
                total = 100,
                title = "",
                display_pct = TRUE,
                status = "custom"
            )
        ),
        tags$style(".progress-bar-custom {background-color: #25c484;}"),
        
        DTOutput("intTable")
    )
)

server <- function(input, output, session) {
    
    for (i in 1:10) {
        updateProgressBar(
            session = session,
            id = "pb2",
            value = i, total = 10
        )
        Sys.sleep(0.2)
    }
    ####==Here I want to close this ProgressBar==######
    
    data <- reactive({
        head(mtcars)
    })
    
    observeEvent(data(),{
        hide("pb2_vis")
    })
    
    output$intTable<- renderDT({data() %>%
            datatable(rownames = FALSE, options = list(dom = 't', pageLength = 200))
    })
    
}

shinyApp(ui = ui, server = server)

在此处输入图像描述


推荐阅读