Skip to content

➑️  Toggle button

Submitted by Arnaud Miribel

Summary

Toggle button just like in Notion!

Functions

stoggle

Displays a toggle widget in Streamlit

Parameters:

Name Type Description Default
summary str

Summary of the toggle (always shown)

required
content str

Content shown after toggling

required
Source code in src/streamlit_extras/stoggle/__init__.py
@extra
def stoggle(summary: str, content: str):
    """
    Displays a toggle widget in Streamlit

    Args:
        summary (str): Summary of the toggle (always shown)
        content (str): Content shown after toggling
    """

    st.write(
        str(
            div(
                style=styles(
                    line_height=1.8,
                )
            )(details(smry(summary), p(content)))
        ),
        unsafe_allow_html=True,
    )

Import:

from streamlit_extras.stoggle import stoggle # (1)!
  1. You should add this to the top of your .py file πŸ› 

Examples

example

def example():
    stoggle(
        "Click me!",
        """πŸ₯· Surprise! Here's some additional content""",
    )
Output (beta)