Multi step form interaction

Hey all.

Is it possible to have something like a multi-step form, like a wizard?

The use case that I am developing this for is something like: (I use 3 different streamlit apps for this now)

I generate a story based on certain parameters.
I click submit, and it generates a storyline.
I can edit that storyline, and when I click submit, I am presented with another form, specifically to use that storyline to create a booklet.
That booklet generation has other parameters that you can set.
When i’m happy with that, I click ‘create book’ and I am presented with, yet another form to work on the final parameters…

All of these have to work independently of each other, so changing something doesn’t rerun the entire interface, only when I click submit (like a st.form) But, how would one add the functionality to show and hide form controls?

Does anyone know, am I perhaps asking a bit too much of Streamlit in this case?

Thank you all!

Hi @Marco_Kotrotsos,

Yes, this use case is doable with Streamlit, mainly through session state. You’ll probably want to store the values of all the inputs in session state and have a variable in session state that indicates which of the steps have been completed by the user, so that when the app reruns after the user hits the “Submit” button on one of the forms, the next form can be displayed.

Here’s an example of a skeleton app

import streamlit as st

def generate_storyline():
    st.session_state["stage"] = "edit_storyline"

def create_booklet():
    st.session_state["stage"] = "final_parameters"

def final_parameters():
    st.session_state["stage"] = "story_generation"

if "stage" not in st.session_state:
    st.session_state["stage"] = "story_generation"

if st.session_state["stage"] == "story_generation":
    with st.form("story_form"):
        submitted = st.form_submit_button(
            "Generate Storyline", on_click=generate_storyline

elif st.session_state["stage"] == "edit_storyline":
    with st.form("edit_story_form"):
        submitted = st.form_submit_button("Create Booklet", on_click=create_booklet)

elif st.session_state["stage"] == "final_parameters":
    with st.form("final_params_form"):
        submitted = st.form_submit_button("Create Book", on_click=final_parameters)

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.