Skip to main content

A little streamlit wizard

Project description

streamlit-wizard

This is an example of creating a wizard within Streamlit.

To use it, create your page objects by inheriting from the Page class in components, and pass the resulting pages into the Wizard class as illustrated in main.py.

Styling

Some custom CSS styling is used for the container. You can fiddle with it in static/style.css

State

Streamlit session state is used to store the current page and to move data between pages. See example_pages.py for an example of how you can retrieve data stored on previous pages. I've not thought this pattern through very deeply, please let me know if there's a better way of doing it - obviously handling state in nested components in complex, see Redux.

Running

pip install -r requirements.txt
streamlit run main.py

Example Usage

from streamlit_wizard import components

class IntroPage(Page):
    def render(self) -> dict:
        st.title("Intro")
        st.write("This is the intro page")
        accept = st.radio(
            "Do you understand that",
            options=["Yes", "No", "Can you repeat the question"],
        )
        return dict(accept=accept)


class FirstPageOfQuestions(Page):
    def render(self) -> dict:
        st.title("Question Page")
        st.write("We will have some questions here")

        # We can access the other page state via session storage if we know what it is called
        # This is presumably not a very robust solution

        did_they_accept = st.session_state["page_state"]["intro"]["accept"]
        st.write(f"On the previous page you selected {did_they_accept}")
        fave_bean = st.selectbox(
            "What is your favourite jelly bean colour", ["Red", "Orange", "Green"]
        )
        return dict(fave_bean=fave_bean)


intro = example_pages.IntroPage(name="intro")
data = example_pages.FirstPageOfQuestions(name="questions")

wizard = components.Wizard(pages=[intro, data])

wizard.render()

Publishing

python3 -m build && python3 -m twine upload dist/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

streamlit_wizard-0.0.3.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

streamlit_wizard-0.0.3-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file streamlit_wizard-0.0.3.tar.gz.

File metadata

  • Download URL: streamlit_wizard-0.0.3.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.4

File hashes

Hashes for streamlit_wizard-0.0.3.tar.gz
Algorithm Hash digest
SHA256 27e97a2059f35517aabc20e6ad720c9288f24e923dc7d2f91ea76f4f9576fdd1
MD5 7fd4b92c98243a6614682fe5835f554d
BLAKE2b-256 adfd62dc7e876c3cc8d7682c617f5330a67024c34ae0d1ca1703fa09c74508ef

See more details on using hashes here.

File details

Details for the file streamlit_wizard-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for streamlit_wizard-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 077db0c6ce82d001872e2898885d14112a2bbfe647b9d828fcd3b2b5c7abb868
MD5 5b200c36d40874037e83104d2ac3efa2
BLAKE2b-256 da419faa4065203fcd48cf936c330450abd8fb2d6eaec85aad272e2280bc2cbd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page