Create Page Skill
Overview
This skill guides you through adding new pages and components to the Streamlit application.
Steps
1. Create a New Page
Streamlit handles multi-page apps automatically if you place scripts in a pages/ directory.
- •Create
app/pages/if it doesn't exist. - •Create a new Python file in
app/pages/, e.g.,app/pages/01_Analysis.py.- •Prefixing with numbers (e.g.,
01_,02_) controls the order in the sidebar.
- •Prefixing with numbers (e.g.,
python
import streamlit as st
st.set_page_config(page_title="Analysis", page_icon="📈")
st.markdown("# Analysis Page")
st.sidebar.header("Analysis")
st.write("This is a new page.")
2. Create Reusable Components
If you have UI logic that is reused, place it in app/components/.
- •Create
app/components/if it doesn't exist. - •Create a module, e.g.,
app/components/charts.py.
python
import streamlit as st
import pandas as pd
import numpy as np
def plot_chart(data):
st.line_chart(data)
- •Import and use it in your pages:
python
from components.charts import plot_chart # ... plot_chart(df)
3. Verify
- •Run the app:
./dc.sh exec streamlit run app/main.py(or check the running instance). - •Navigate to the new page via the sidebar.