【问题标题】:Use "withProgress" in shiny在闪亮中使用“withProgress”
【发布时间】:2017-06-25 15:19:43
【问题描述】:

我试图了解“进度指示器”是如何工作的,因此我创建了一个循环(虚构),它需要大约 7 秒 (1.8GHz) 才能运行。 我想在用户单击 Go 按钮后显示进度条!

这是代码:

    ui <- fluidPage(
  headerPanel("Progress indicators"),
  sidebarPanel(
    numericInput("n", "N:", min = 0, max = 100, value = 50000),
    br(),
    actionButton("goButton", "Go!")

  ),
  mainPanel(
    verbatimTextOutput("nText")
  )
)

server <- function(input, output) {

  fictional <-  reactive({
  n=input$n
  p = rep(0,n)
  for(j in 1:n){
      data1=rnorm(1000,1,2)
      data2=runif(1000,1,2)
      p[j] =  min(data1,data2)
     }
    pw1 =  mean(p)
    return(pw1)
})
  ntext <- eventReactive(input$goButton, { fictional()})

  output$nText <- eventReactive(input$goButton, {

    withProgress(message = 'Progress indicators', {
    ntext()
     })
  })
}
shinyApp(ui, server)

我试图使用 withProgress 但我不知道如何使用它来包装代码,因为当我点击 Go!它向我显示进度条但停止。循环结束时消失

有什么建议吗?

提前谢谢你!

【问题讨论】:

    标签: r shiny shinydashboard


    【解决方案1】:

    ?withProgress- 你必须告诉你的进度条进度,例如

       ui <- fluidPage(
      headerPanel("Progress indicators"),
      sidebarPanel(
        numericInput("n", "N:", min = 0, max = 100, value = 50000),
        br(),
        actionButton("goButton", "Go!")
    
      ),
      mainPanel(
        verbatimTextOutput("nText")
      )
    )
    
    server <- function(input, output) {
    
      fictional <-  reactive({
      n=input$n
      p = rep(0,n)
      for(j in 1:n){
          if (j%%100==0) incProgress(100/n)
          data1=rnorm(1000,1,2)
          data2=runif(1000,1,2)
          p[j] =  min(data1,data2)
         }
        pw1 =  mean(p)
        return(pw1)
    })
      ntext <- eventReactive(input$goButton, { fictional()})
    
      output$nText <- eventReactive(input$goButton, {
    
        withProgress(message = 'Progress indicators', {
        ntext()
         })
      })
    }
    shinyApp(ui, server)
    

    【讨论】:

      猜你喜欢
      • 2021-01-10
      • 1970-01-01
      • 2020-01-18
      • 1970-01-01
      • 2019-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-25
      相关资源
      最近更新 更多