2017-06-25 6 views
1

「進行状況インジケータ」がどのように光るかを理解しようとしていますので、約7秒(1.8GHz)のループを作成しました。 ユーザーがボタンをクリックした後に進行状況バーを表示したい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){ 
     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を使用しようとしていたが、私は行くにクリックしたときので、コードをラップするためにそれを使用する方法がわかりません!プログレスバーが表示されますが、停止します。ループ終了時に消える

何か提案がありますか?

ありがとうございます!

答えて

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) 
関連する問題