Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201943

R Shiny - Updating the value of a selectInput and progressBar simultaneously

$
0
0

The app below contains an actionButton, a shinyWidgets::progressBar and a selectInput:

enter image description here

When the Start button is clicked, an observeEvent is triggered in which I loop through the numbers 1-10 and increment the progress bar at each iteration. I would also like to update the value of the selectInput at each iteration but updateSelectInput does not work as expected. Instead of updating in tandem with the progress bar, the selectInput value is only updated once the loop has terminated. I don't understand why updateProgressBar works here but updateSelectInput doesn't?

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  actionButton(inputId = "go", label = "Start"), #, onclick = "$('#my-modal').modal().focus();"
  shinyWidgets::progressBar(id = "pb", value = 0, display_pct = TRUE),
  selectInput('letters', 'choose', letters)
)

server <- function(input, output, session) {

  observeEvent(input$go, {

    shinyWidgets::updateProgressBar(session = session, id = "pb", value = 0) # reinitialize to 0 if you run the calculation several times

    for (i in 1:10) {

      updateProgressBar(session = session, id = "pb", value = 100/10*i)

      updateSelectInput(session, 'letters', selected = letters[i])

      Sys.sleep(.5)

    }

  })

}

shinyApp(ui = ui, server = server)

Viewing all articles
Browse latest Browse all 201943

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>