[英]Progress bar in R shiny for loop
我在使用進度條來配合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)
我不確定是否可以調整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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.