首页 文章

进度条在R闪亮的循环

提问于
浏览
0

我无法获得进度条以使用闪亮的selectInput函数 . 它给出了用户选择加载到页面的数据的进度,但不是应用程序执行它应该对数据做什么的循环 . 这是我到目前为止:

ui <- fluidPage(  
  titlePanel("Upload Files"),  
  sidebarLayout(  
    sidebarPanel(  
      fileInput("upload", "Select Files",  
                multiple = TRUE,  
                accept = c("text/csv",  
                           "text/comma-separated-values,text/plain"))  
    ),  
    mainPanel(  
      tableOutput("table")  
    )  
  )  
)  

server <- function(input, output) {  
  observeEvent(input$upload, {for (i in 1:length(input$upload$datapath)) {  *code to execute*  
}})  
output$table <- renderTable(  
print(input$upload$name))  
}  
shinyApp(ui,server)

1 回答

  • 2

    我不确定你是否可以调整fileInput的加载条来响应一个循环,但是这里有一个新进度条的替代方案 .

    ui <- fluidPage( 
    
      # With this tag you can change the position and the size of the progress bar
      # Without it, the bar will be at the bottom right corner of the screen
      tags$head(tags$style(".shiny-notification {position: fixed; 
                                                 opacity: 1 ;
                           top: 35% ;
                           left: 40% ;
                           height: 50px;
                           width: 300px}")),
    
      titlePanel("Upload Files"),  
      sidebarLayout(  
        sidebarPanel(  
          fileInput("upload", "Select Files",  
                    multiple = TRUE,  
                    accept = c("text/csv",  
                               "text/comma-separated-values,text/plain"))  
        ),  
        mainPanel(  
          tableOutput("table")  
        )  
      )  
    )  
    
    server <- function(input, output) { 
    
      observeEvent(input$upload, {
    
        # wrap the loop execution in withProgress
        withProgress(
          message='Please wait',
          detail='Doing important stuff...',
          value=0, {
    
            for (i in 1:5) {  # changed the loop for demonstration purposes
    
              Sys.sleep(0.8)  # pretending to execute code
              incProgress(amount=1/5)
            }
          })
      })
    
      output$table <- renderTable(print(input$upload$name))  
    }  
    
    shinyApp(ui,server)
    

相关问题