Avoid rerunning for intermediate values for number_input, slider etc

  1. How can i pick the last value of the number_input, and avoid rerunning for the intermediate values?
  2. Run only when all the variables’ values in number_inputs are finalized using +/- sign.
    Solution: I have put one checkbox(condition-yes/no) so that it doesn’t run the heavy code unless user selects it.
  3. When somebody keeps on inc/dec the value, page gets reloaded and all the entered values are set to default.
  4. How can i avoid reloading of page unless user does it purposefully? It usually happens in above cases.

Hi @ansks, welcome to the forum :wave:

  1. Currently, the number_input widget will trigger a re-run if you use the +/- stepper or if you type a value and press enter or type a value and click somewhere else on the page. There is no way to avoid this at the moment.

  2. Happy to hear you found a workaround for this. Please see the conversation here for other approaches Have a widget not trigger an immediate update?

  3. Apologies but I don’t fully understand the question. Widget values should not be reset as we maintain widget state across re-runs. Perhaps a code snippet would help me understand the issue here better.

  4. See my response to 3

Hi @Jonathan_Rhone,

Thank you very much for your response.

Question 3:

  • I wanted to ask how can we just pick the last value selected by the user when user is using +/- button for changing the input(one way is to use steps inside the input_value). Is the waiting time that we can introduce so that it doesn’t run the code every time unless user is done inputting?

Question 4:

  • Page gets reloaded when there are multiple inputs entered, and code is bit heavy(eg. optimization). Is there a better way to stop crashing the page.

Thank you for answering so patiently and clearly,

Regards,
Anshul

Hi @ansks,

All your questions sound similar in that case and I’d refer you again to the post at Have a widget not trigger an immediate update? for a comprehensive discussion on approaches and possible solutions.

One way to do it is to put all your heavy calculations behind an st.button().

if st.button('button'):
   ... heavy calculations ...

If there is something that is not working for you after following one of the approaches please let us know!

2 Likes