Build a Streamlit App in Minutes¶
Getting your Streamlit app connected to SweatStack is quick and easy. This guide will walk you through creating a simple but functional Streamlit application that authenticates with SweatStack and displays activity data.
Get API Credentials¶
Before building your app, you'll need API credentials:
- Go to app.sweatstack.no/settings/api
- Click the "Create Application" button at the bottom of the page and fill out the details of your application
- After saving, create a secret for your application. Important: Treat this secret as a password and keep it safe.
- Copy and paste your
client_id
andclient_secret
into the code below.
Quick Example¶
Here's a complete working example of a Streamlit app that authenticates with SweatStack and displays the user's latest activity.
app.py
import streamlit as st
from sweatstack.streamlit import StreamlitAuth
auth = StreamlitAuth(
client_id="{your_client_id}",
client_secret="{your_client_secret}",
redirect_uri="http://localhost:8501",
)
with st.sidebar:
auth.authenticate()
if not auth.is_authenticated():
st.stop()
st.write("# Welcome to SweatStack!")
latest_activity = auth.client.get_latest_activity()
st.write(latest_activity)
Run your app with:
uv run --with "sweatstack[streamlit]" streamlit run app.py
Further Building¶
Here are some quick ways to enhance your SweatStack Streamlit app:
- Use
auth.select_user()
to allow users to switch between their accounts. - Use
auth.select_sport()
to filter activities by sport. - Use
auth.select_metric()
to select a metric to display. - Use
auth.select_activity()
to select an activity and display its details.
Warning
Remember, when using Streamlit with SweatStack, always use the auth.client
instance for making API calls instead of the global methods, as explained in the Streamlit integration documentation.