Spaces:
Build error
Build error
Commit ·
c9ce4bd
1
Parent(s): cb3d0c2
Upload 6 files
Browse files- app.py +12 -0
- apps/data_stats.py +15 -0
- apps/home.py +18 -0
- data/create_data.py +7 -0
- multiapp.py +47 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from multiapp import MultiApp
|
| 3 |
+
from apps import home, data_stats # import your app modules here
|
| 4 |
+
|
| 5 |
+
app = MultiApp()
|
| 6 |
+
|
| 7 |
+
# Add all your application here
|
| 8 |
+
app.add_app("Home", home.app)
|
| 9 |
+
app.add_app("Data Stats", data_stats.app)
|
| 10 |
+
|
| 11 |
+
# The main app
|
| 12 |
+
app.run()
|
apps/data_stats.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from data.create_data import create_table
|
| 5 |
+
|
| 6 |
+
def app():
|
| 7 |
+
st.title('Data Stats')
|
| 8 |
+
|
| 9 |
+
st.write("This is a sample data stats in the mutliapp.")
|
| 10 |
+
st.write("See `apps/data_stats.py` to know how to use it.")
|
| 11 |
+
|
| 12 |
+
st.markdown("### Plot Data")
|
| 13 |
+
df = create_table()
|
| 14 |
+
|
| 15 |
+
st.line_chart(df)
|
apps/home.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
from data.create_data import create_table
|
| 5 |
+
|
| 6 |
+
def app():
|
| 7 |
+
st.title('Home')
|
| 8 |
+
|
| 9 |
+
st.write("This is a sample home page in the mutliapp.")
|
| 10 |
+
st.write("See `apps/home.py` to know how to use it.")
|
| 11 |
+
|
| 12 |
+
st.markdown("### Sample Data")
|
| 13 |
+
df = create_table()
|
| 14 |
+
st.write(df)
|
| 15 |
+
|
| 16 |
+
st.write('Navigate to `Data Stats` page to visualize the data')
|
| 17 |
+
|
| 18 |
+
|
data/create_data.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
def create_table(n=7):
|
| 5 |
+
df = pd.DataFrame({"x": range(1, 11), "y": n})
|
| 6 |
+
df['x*y'] = df.x * df.y
|
| 7 |
+
return df
|
multiapp.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Frameworks for running multiple Streamlit applications as a single app.
|
| 2 |
+
"""
|
| 3 |
+
import streamlit as st
|
| 4 |
+
|
| 5 |
+
class MultiApp:
|
| 6 |
+
"""Framework for combining multiple streamlit applications.
|
| 7 |
+
Usage:
|
| 8 |
+
def foo():
|
| 9 |
+
st.title("Hello Foo")
|
| 10 |
+
def bar():
|
| 11 |
+
st.title("Hello Bar")
|
| 12 |
+
app = MultiApp()
|
| 13 |
+
app.add_app("Foo", foo)
|
| 14 |
+
app.add_app("Bar", bar)
|
| 15 |
+
app.run()
|
| 16 |
+
It is also possible keep each application in a separate file.
|
| 17 |
+
import foo
|
| 18 |
+
import bar
|
| 19 |
+
app = MultiApp()
|
| 20 |
+
app.add_app("Foo", foo.app)
|
| 21 |
+
app.add_app("Bar", bar.app)
|
| 22 |
+
app.run()
|
| 23 |
+
"""
|
| 24 |
+
def __init__(self):
|
| 25 |
+
self.apps = []
|
| 26 |
+
|
| 27 |
+
def add_app(self, title, func):
|
| 28 |
+
"""Adds a new application.
|
| 29 |
+
Parameters
|
| 30 |
+
----------
|
| 31 |
+
func:
|
| 32 |
+
the python function to render this app.
|
| 33 |
+
title:
|
| 34 |
+
title of the app. Appears in the dropdown in the sidebar.
|
| 35 |
+
"""
|
| 36 |
+
self.apps.append({
|
| 37 |
+
"title": title,
|
| 38 |
+
"function": func
|
| 39 |
+
})
|
| 40 |
+
|
| 41 |
+
def run(self):
|
| 42 |
+
app = st.sidebar.radio(
|
| 43 |
+
'Go To',
|
| 44 |
+
self.apps,
|
| 45 |
+
format_func=lambda app: app['title'])
|
| 46 |
+
|
| 47 |
+
app['function']()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
numpy
|
| 3 |
+
pandas
|