Best practice for sequence of user-inputs?

I want to make an app with the following sequential workflow:

  • user specifies dataset file F
    • app uploads the dataset from F, displays some rows
  • user selects column Y to predict, which columns CAT to treat as categorical
    • app trains model to predict Y, treating CAT as categorical
  • user selects which row R to analyze
    • app displays analysis for row R

I want the app to wait for the user to supply the requisite inputs before proceeding to the next stage. It can all be in one page, with scrolling down (i.e. I don’t need a fancy multi-tab layout).

I tried doing this in a simple way with elements like st.number_input() to get row number, and st.button to indicate the user is done inputting and to continue the processing, but I think because the app just restarts from the top each time, I’m not getting what I want.

I suspect st.cache() is what I want, so that even though the app re-starts from the top, it doesn’t “feel” that way? Or if there is another trick to this, please let me know… I think this is a fairly simple and common scenario.

Thanks

Actually got it working used the solution using st.State posted here

by @andfanilo

Basic idea is to hold on to various “expensive-to-compute” things, like models, data, etc in the state object, so they are preserved between runs triggered by user buttons/input.

2 Likes

Glad you figured it out!