在SHILINY中使用&WITH&PROCESS&QOOT; [英] Use "withProgress" in shiny
本文介绍了在SHILINY中使用&WITH&PROCESS&QOOT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想了解一下"进度指示器"在Slight中是如何工作的,所以我创建了一个循环(虚构的),运行时间约为7秒(1.8 GHz)。 我想在用户单击按钮开始后显示进度条!
代码如下:
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)
我试图使用With Progress,但我不知道如何使用它来包装代码,因为当我点击Go!它会显示进度条,但会停止。循环结束时消失
有什么建议吗?
提前感谢!
推荐答案
查看?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)
这篇关于在SHILINY中使用&WITH&PROCESS&QOOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文