How to run something only after all selections of a multi select input have been made

Here is my question. I have a Shiny App in with some a series of select inputs that the user must go through and make selections on. The LAST selection in a multi select. Once he/she has made all of the selections, then a reactive event occurs where a sql statement is created and a database is queried...the results are written to a csv file. This code works. However , it runs that final reactive each time the user selects more on the multil select. I want the even to occur only after all of the those selection in the multi - select have been made... Any suggestions..?

Add something like

req(all(my_multi_select_options %in% input$my_multi_select))

Hi @cmickel. You may use debounce to delay the fire of reactive signal and prevent fire signals frequently during multi selection.

Thanks, woodward! I used req but only something like req(input$my_multi_select) . I think this might get it for me.


This is something I've never heard of but I'll look into it. I appreciate your help on this!

Why not have the user click a button when all the input is complete?

Well, I wanted to design it so that the button wouldn't appear until they'd made all of their selections first. In fact, each of the select inputs(except the first) appear after the one prior to it because the data displayed in each subsequent input is dependent on the choice before. I didn't want to give the user the ability to even push the button until they were done with that process. But you're right...I could just have the button displayed and put in checks to validate the necessary data was selected. I just didn't want to.

Maybe I'm not doing something right or I'm still to new at this but I tried something like you suggested and it didn't seem to work. Here is the input on the ui side:

selectInput(inputId = "selectSegment", "Select a question segment", NULL, multiple = TRUE,
selectize = TRUE, width = "100%"))

Here is the event on the server side(without the change you suggested) that I want to kick off once the user is done making the selections from this:

outputTable <- reactive({


What would you put in the if statement?

Oh I misunderstood your question. How do you know when the last multiselect has been made?

outputTable <- reactive({

   req(input$selectSegment) # ensure a selection exists



This does the same thing. Each time I pick and add to the selection the event fires. But thanks for the help. There's got to be a way to tell the thing to not fire until the user is out of the select input but I'm just not able to do it.

Yes that's the way Shiny usually works. If you want it to wait, then usual method is to add an actionButton that the user click when they're ready to calculate.

That's what I ended up doing. I probably should have just done that a week ago...I spent a lot of time experimenting with this. LOL. Anyway, I sure appreciate your help!

You can probably do something clever by attaching a javascript event handler to the selectInput widget, but this might be more effort than it is worth.

Yeah, I actually started down that path for a bit. Maybe I will dig into it again later.

1 Like