1

I am having trouble getting a progress bar to work with the selectInput function in shiny. It gives the progress of the data the user selects loading to the page, but not the app executing the loop of what it is supposed to do with the data. This is what I have so far:

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 Answer 1

4

I'm not sure if you can adapt the load bar of fileInput to respond to a loop, but here's an alternative with a new progress bar.

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) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.