Skip to main content

Streamlit Super App

Enhance your Streamlit app development experience with Streamlit Super App! This package provides features that streamline the creation and management of multipage apps and offers improved state management for widgets.

Features

  • Multipage/Tree Router: Automatically generate multi-page routing based on folder structure.
  • Persistent State Management: Seamlessly manage the state of widgets across different pages.

Installation

Install Streamlit Super App using pip:

pip install streamlit-superapp

Getting Started

Multipage Routing

Create a pages folder in the root directory of your Streamlit app and organize your pages as shown below:

pages/
├─  __init__.py
└─  hello/__init__.py
  • You can go beyond that, create as many levels as you want!

For instance, pages/hello/__init__.py can be:

import streamlit as st

NAME = "Demo"
DESCRIPTION = "Sample page to demonstrate Streamlit Super App."
ICON = "🌍"

def main():
    st.write("Hello World!")

In your main file, call streamlit_superapp's "run" function

import streamlit_superapp as app

app.run()

Managing DataFrame State and Editing

Easily edit and manage the state of DataFrames.

import pandas as pd
import streamlit as st
from streamlit_superapp.state import State

ICON = "📊"

def main():
    state = State("df", default_value=get_base_input())


    with st.sidebar:
        if st.button("✖️ Multiply"):
            # The "state.value" is always the most updated value
            # So we can manipulate it before rendering it again
            state.initial_value = calculate(state.value)

        if st.button("🔄 Reset"):
            # Forcing a value update before rendering
            state.initial_value = get_base_input()

    # setting the "initial_value" and "key" is mandatory
    df = st.data_editor(data=state.initial_value, key=state.key, hide_index=True)

    # binding the new value to the state is mandatory!
    # plus you get the previous value for free!
    previous_df = state.bind(df)

    if not df.equals(previous_df):
        st.success("Data changed!")


def get_base_input():
    return pd.DataFrame(index=[0, 1, 2], columns=["a", "b"], dtype=float)


def calculate(df: pd.DataFrame):
    df["result"] = df["a"] * df["b"]

    return df

Basic Counter

Create counters with persistent state.

import streamlit as st
from streamlit_superapp import State

NAME = "Counter"
TAG = "{A:}📚 Studies" # This page will appear in a group "📚 Studies" at the top of a index page
ICON = "🔢"

def main(page):
    counter = State("counter", default_value=0, key=page)

    if st.button("Increment"):
        # This is the same as binding a new value
        counter.value += 1

    # Initial value only updates after changing pages
    # or if we update it manually
    st.write(f"initial_value:" {counter.initial_value})
    st.write(f"current value: {counter.value}")

Shared State Across Pages

Maintain the state of TextInput across different pages.

import streamlit as st
from streamlit_superapp import State

NAME = "Persistent Text Input"

def main():

    # You can access the state "text" on another page too!
    state = State("text", default_value="Wilian")

    text = st.text_input("Your Name", value=state.initial_value, key=state.key)

    previous_text = state.bind(text)

    if text != previous_text:
        st.success("Input changed")

    st.success(f"Hello {text}!")

Page Private State

Create a persistent TextInput that is private to a page.

from streamlit_superapp import State, Page
import streamlit as st

NAME = "Page Only State"

# Super app will provide the current page to your function
def main(page: Page):

    # Providing the state with the page as key will make it private
    # Even tho it has the same "text" key state
    state = State("text", default_value="", key=page)

    value = st.text_input("This is not shared between pages", value=state.initial_value)

    previous_value = state.bind(value)

    st.write(value)

Contributing

We welcome contributions to Streamlit Super App! Please feel free to open issues or submit pull requests.

License

Streamlit Super App is licensed under the MIT License.


Release files for streamlit-superapp 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for streamlit-superapp 1.3.0
File Size Uploaded
streamlit_superapp-1.3.0.tar.gz 3.4 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for streamlit-superapp 1.3.0
File Interpreter ABI Platform
streamlit_superapp-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.0 MB

Release files / streamlit_superapp-1.3.0.tar.gz

Download URL streamlit_superapp-1.3.0.tar.gz
Size 3.4 MB
Tags Source
SHA-256 checksum
How to use checksums
3ec9e76f79df42065eb4439087fef232857e2535d5f238cc777cfa2b457399fc
BLAKE2b-256 checksum
How to use checksums
85c77cdd8fd8c6e7c10e9a46647812c073a32a1a33d23191bd083d81667702bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Release files / streamlit_superapp-1.3.0-py3-none-any.whl

Download URL streamlit_superapp-1.3.0-py3-none-any.whl
Size 4.6 MB
Tags Python 3
SHA-256 checksum
How to use checksums
b48e87f148d642aadc5eb77542b955be71d3cc8534900cb29200c6f4ec9ecf80
BLAKE2b-256 checksum
How to use checksums
49cb12956ac2a12d30487898ccec662d39beaedd51954871b0f92f9f8269812d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files

1.2.0

2 release files

1.1.34

2 release files

1.1.33

2 release files

1.1.32

2 release files

1.1.31

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page