Spaces:
Runtime error
Runtime error
Copy https://github.com/whitphx/stlite/tree/main/packages/sharing-editor/public/samples/011_component_gallery
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- app.py +51 -0
- pages/charts.area_chart.py +12 -0
- pages/charts.audio.py +34 -0
- pages/charts.bar_chart.py +12 -0
- pages/charts.bokeh_chart.py +12 -0
- pages/charts.graphviz_chart.py +25 -0
- pages/charts.image.py +20 -0
- pages/charts.line_chart.py +12 -0
- pages/charts.map.py +14 -0
- pages/charts.plotly_chart.py +24 -0
- pages/charts.pydeck_chart.py +45 -0
- pages/charts.pyplot.py +14 -0
- pages/charts.vega_lite_chart.py +24 -0
- pages/charts.video.py +20 -0
- pages/data.dataframe.py +12 -0
- pages/data.dataframe1.py +12 -0
- pages/data.dataframe2.py +23 -0
- pages/data.json.py +5 -0
- pages/data.table.py +12 -0
- pages/flower.png +0 -0
- pages/forms.form1.py +13 -0
- pages/forms.form2.py +8 -0
- pages/layout.columns1.py +20 -0
- pages/layout.columns2.py +16 -0
- pages/layout.container1.py +10 -0
- pages/layout.container2.py +8 -0
- pages/layout.expander.py +14 -0
- pages/layout.tabs1.py +14 -0
- pages/layout.tabs2.py +11 -0
- pages/metric.example1.py +3 -0
- pages/metric.example2.py +6 -0
- pages/metric.example3.py +4 -0
- pages/requirements.txt +11 -0
- pages/text.caption.py +3 -0
- pages/text.code.py +5 -0
- pages/text.header.py +3 -0
- pages/text.latex.py +9 -0
- pages/text.markdown.py +3 -0
- pages/text.subheader.py +3 -0
- pages/text.text.py +3 -0
- pages/text.title.py +3 -0
- pages/text.write1.py +3 -0
- pages/text.write2.py +7 -0
- pages/text.write3.py +13 -0
- pages/widget.button.py +6 -0
- pages/widget.checkbox.py +5 -0
- pages/widget.color_picker.py +4 -0
- pages/widget.date_input.py +5 -0
- pages/widget.download_button.py +41 -0
- pages/widget.file_uploader.py +6 -0
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.title("Streamlit Component Gallery")
|
4 |
+
|
5 |
+
st.image("https://docs.streamlit.io/logo.svg")
|
6 |
+
|
7 |
+
st.markdown("""
|
8 |
+
This _stlite_ sample app contains the demos embedded on the Streamlit official document (https://docs.streamlit.io/).
|
9 |
+
|
10 |
+
**👈 Select a demo from the sidebar** to see some examples
|
11 |
+
of Streamlit built-in components!
|
12 |
+
""")
|
13 |
+
|
14 |
+
st.markdown("""
|
15 |
+
### Notes
|
16 |
+
|
17 |
+
The page files (`pages/*`) are copied from [the Streamlit official document sample directory (`docs/python/api-examples-source`)](https://github.com/streamlit/docs/tree/5e62035f0ea36b211232ae3a5778dcd8ffdcac15/python/api-examples-source)
|
18 |
+
excluding the sub directories.
|
19 |
+
|
20 |
+
The following files have been changed:
|
21 |
+
* `widget.download_button.py`:
|
22 |
+
A local file path in the source code has been rewritten to adjust to the directory structure of this sample app.
|
23 |
+
|
24 |
+
Due to the browser environment limitations,
|
25 |
+
some components do not work well.
|
26 |
+
The known issues are listed at https://github.com/whitphx/stlite#limitations.
|
27 |
+
|
28 |
+
### License
|
29 |
+
As written above, the files `pages/*` are copied from `https://github.com/streamlit/docs` with some modifications,
|
30 |
+
therefore, the license applied to the source, the Apache-2.0 license, is also applied to this sample as follows.
|
31 |
+
|
32 |
+
#### Apache-2.0 license
|
33 |
+
|
34 |
+
Copyright Streamlit Inc.
|
35 |
+
|
36 |
+
Copyright Yuichiro Tachibana
|
37 |
+
|
38 |
+
Licensed under the Apache License, Version 2.0 (the “License”);
|
39 |
+
you may not use this file except in compliance with the License.
|
40 |
+
You may obtain a copy of the License at
|
41 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
42 |
+
|
43 |
+
Unless required by applicable law or agreed to in writing, software
|
44 |
+
distributed under the License is distributed on an “AS IS” BASIS,
|
45 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
46 |
+
|
47 |
+
See the License for the specific language governing permissions and
|
48 |
+
limitations under the License.
|
49 |
+
|
50 |
+
See https://github.com/streamlit/docs/blob/main/LICENSE
|
51 |
+
""")
|
pages/charts.area_chart.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
@st.experimental_memo
|
6 |
+
def load_data():
|
7 |
+
df = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"])
|
8 |
+
return df
|
9 |
+
|
10 |
+
chart_data = load_data()
|
11 |
+
|
12 |
+
st.area_chart(chart_data)
|
pages/charts.audio.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
|
5 |
+
@st.experimental_memo
|
6 |
+
def read_file_from_url(url):
|
7 |
+
headers = {
|
8 |
+
"User-Agent": "StreamlitDocs/1.5.0 (https://docs.streamlit.io; [email protected])"
|
9 |
+
}
|
10 |
+
return requests.get(url, headers=headers).content
|
11 |
+
|
12 |
+
|
13 |
+
file_bytes = read_file_from_url(
|
14 |
+
"https://upload.wikimedia.org/wikipedia/commons/c/c4/Muriel-Nguyen-Xuan-Chopin-valse-opus64-1.ogg"
|
15 |
+
)
|
16 |
+
|
17 |
+
st.audio(file_bytes, format="audio/ogg")
|
18 |
+
|
19 |
+
st.write(
|
20 |
+
"""
|
21 |
+
#### Audio credit:
|
22 |
+
|
23 |
+
Performer: _Muriel Nguyen Xuan_ and _Stéphane Magnenat_
|
24 |
+
|
25 |
+
Composer: Frédéric Chopin
|
26 |
+
|
27 |
+
License: Creative Commons Attribution-Share Alike 4.0 International, 3.0 Unported, 2.5 Generic, 2.0 Generic and 1.0 Generic license.
|
28 |
+
https://creativecommons.org/licenses/by-sa/4.0/
|
29 |
+
|
30 |
+
URL:
|
31 |
+
https://upload.wikimedia.org/wikipedia/commons/c/c4/Muriel-Nguyen-Xuan-Chopin-valse-opus64-1.ogg
|
32 |
+
|
33 |
+
"""
|
34 |
+
)
|
pages/charts.bar_chart.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
@st.experimental_memo
|
6 |
+
def load_data():
|
7 |
+
df = pd.DataFrame(np.random.randn(50, 3), columns=["a", "b", "c"])
|
8 |
+
return df
|
9 |
+
|
10 |
+
chart_data = load_data()
|
11 |
+
|
12 |
+
st.bar_chart(chart_data)
|
pages/charts.bokeh_chart.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from bokeh.plotting import figure
|
3 |
+
|
4 |
+
|
5 |
+
x = [1, 2, 3, 4, 5]
|
6 |
+
y = [6, 7, 2, 4, 5]
|
7 |
+
|
8 |
+
p = figure(title="simple line example", x_axis_label="x", y_axis_label="y")
|
9 |
+
|
10 |
+
p.line(x, y, legend_label="Trend", line_width=2)
|
11 |
+
|
12 |
+
st.bokeh_chart(p)
|
pages/charts.graphviz_chart.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import graphviz as graphviz
|
3 |
+
|
4 |
+
@st.experimental_memo
|
5 |
+
def load_graph():
|
6 |
+
# Create a graphlib graph object
|
7 |
+
graph = graphviz.Digraph()
|
8 |
+
graph.edge("run", "intr")
|
9 |
+
graph.edge("intr", "runbl")
|
10 |
+
graph.edge("runbl", "run")
|
11 |
+
graph.edge("run", "kernel")
|
12 |
+
graph.edge("kernel", "zombie")
|
13 |
+
graph.edge("kernel", "sleep")
|
14 |
+
graph.edge("kernel", "runmem")
|
15 |
+
graph.edge("sleep", "swap")
|
16 |
+
graph.edge("swap", "runswap")
|
17 |
+
graph.edge("runswap", "new")
|
18 |
+
graph.edge("runswap", "runmem")
|
19 |
+
graph.edge("new", "runmem")
|
20 |
+
graph.edge("sleep", "runmem")
|
21 |
+
return graph
|
22 |
+
|
23 |
+
graph = load_graph()
|
24 |
+
|
25 |
+
st.graphviz_chart(graph)
|
pages/charts.image.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
IMAGE_URL = "https://images.unsplash.com/photo-1548407260-da850faa41e3?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1487&q=80"
|
4 |
+
|
5 |
+
st.image(IMAGE_URL, caption="Sunrise by the mountains")
|
6 |
+
|
7 |
+
st.write(
|
8 |
+
"""
|
9 |
+
#### Image credit:
|
10 |
+
|
11 |
+
Creator: User _Neil Iris (@neil_ingham)_ from _Unsplash_
|
12 |
+
|
13 |
+
License: Do whatever you want.
|
14 |
+
https://unsplash.com/license
|
15 |
+
|
16 |
+
URL:
|
17 |
+
https://unsplash.com/photos/I2UR7wEftf4
|
18 |
+
|
19 |
+
"""
|
20 |
+
)
|
pages/charts.line_chart.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
@st.experimental_memo
|
6 |
+
def load_data():
|
7 |
+
df = pd.DataFrame(np.random.randn(20, 3), columns=["a", "b", "c"])
|
8 |
+
return df
|
9 |
+
|
10 |
+
chart_data = load_data()
|
11 |
+
|
12 |
+
st.line_chart(chart_data)
|
pages/charts.map.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
@st.experimental_memo
|
6 |
+
def load_data():
|
7 |
+
df = pd.DataFrame(
|
8 |
+
np.random.randn(1000, 2) / [50, 50] + [37.76, -122.4], columns=["lat", "lon"]
|
9 |
+
)
|
10 |
+
return df
|
11 |
+
|
12 |
+
df = load_data()
|
13 |
+
|
14 |
+
st.map(df)
|
pages/charts.plotly_chart.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import plotly.figure_factory as ff
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
@st.experimental_memo
|
6 |
+
def load_data():
|
7 |
+
# Add histogram data
|
8 |
+
x1 = np.random.randn(200) - 2
|
9 |
+
x2 = np.random.randn(200)
|
10 |
+
x3 = np.random.randn(200) + 2
|
11 |
+
|
12 |
+
# Group data together
|
13 |
+
hist_data = [x1, x2, x3]
|
14 |
+
return hist_data
|
15 |
+
|
16 |
+
hist_data = load_data()
|
17 |
+
|
18 |
+
group_labels = ["Group 1", "Group 2", "Group 3"]
|
19 |
+
|
20 |
+
# Create distplot with custom bin_size
|
21 |
+
fig = ff.create_distplot(hist_data, group_labels, bin_size=[0.1, 0.25, 0.5])
|
22 |
+
|
23 |
+
# Plot!
|
24 |
+
st.plotly_chart(fig)
|
pages/charts.pydeck_chart.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import pandas as pd
|
3 |
+
import pydeck as pdk
|
4 |
+
import streamlit as st
|
5 |
+
|
6 |
+
|
7 |
+
@st.experimental_memo
|
8 |
+
def load_data():
|
9 |
+
return pd.DataFrame(
|
10 |
+
np.random.randn(1000, 2) / [50, 50] + [37.76, -122.4], columns=["lat", "lon"]
|
11 |
+
)
|
12 |
+
|
13 |
+
|
14 |
+
df = load_data()
|
15 |
+
|
16 |
+
st.pydeck_chart(
|
17 |
+
pdk.Deck(
|
18 |
+
map_style=None,
|
19 |
+
initial_view_state=pdk.ViewState(
|
20 |
+
latitude=37.76,
|
21 |
+
longitude=-122.4,
|
22 |
+
zoom=11,
|
23 |
+
pitch=50,
|
24 |
+
),
|
25 |
+
layers=[
|
26 |
+
pdk.Layer(
|
27 |
+
"HexagonLayer",
|
28 |
+
data=df,
|
29 |
+
get_position="[lon, lat]",
|
30 |
+
radius=200,
|
31 |
+
elevation_scale=4,
|
32 |
+
elevation_range=[0, 1000],
|
33 |
+
pickable=True,
|
34 |
+
extruded=True,
|
35 |
+
),
|
36 |
+
pdk.Layer(
|
37 |
+
"ScatterplotLayer",
|
38 |
+
data=df,
|
39 |
+
get_position="[lon, lat]",
|
40 |
+
get_color="[200, 30, 0, 160]",
|
41 |
+
get_radius=200,
|
42 |
+
),
|
43 |
+
],
|
44 |
+
)
|
45 |
+
)
|
pages/charts.pyplot.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
|
5 |
+
@st.experimental_memo
|
6 |
+
def load_fig():
|
7 |
+
arr = np.random.normal(1, 1, size=100)
|
8 |
+
fig, ax = plt.subplots()
|
9 |
+
ax.hist(arr, bins=20)
|
10 |
+
return fig, ax
|
11 |
+
|
12 |
+
fig, ax = load_fig()
|
13 |
+
|
14 |
+
st.pyplot(fig)
|
pages/charts.vega_lite_chart.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
@st.experimental_memo
|
6 |
+
def load_data():
|
7 |
+
df = pd.DataFrame(np.random.randn(200, 3), columns=["a", "b", "c"])
|
8 |
+
return df
|
9 |
+
|
10 |
+
df = load_data()
|
11 |
+
|
12 |
+
st.vega_lite_chart(
|
13 |
+
df,
|
14 |
+
{
|
15 |
+
"mark": {"type": "circle", "tooltip": True},
|
16 |
+
"encoding": {
|
17 |
+
"x": {"field": "a", "type": "quantitative"},
|
18 |
+
"y": {"field": "b", "type": "quantitative"},
|
19 |
+
"size": {"field": "c", "type": "quantitative"},
|
20 |
+
"color": {"field": "c", "type": "quantitative"},
|
21 |
+
},
|
22 |
+
},
|
23 |
+
use_container_width=True,
|
24 |
+
)
|
pages/charts.video.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
VIDEO_URL = "https://static.streamlit.io/examples/star.mp4"
|
4 |
+
|
5 |
+
st.video(VIDEO_URL)
|
6 |
+
|
7 |
+
st.write(
|
8 |
+
"""
|
9 |
+
#### Video credit:
|
10 |
+
|
11 |
+
Creator: User _fxxu_ from _Pixabay_.
|
12 |
+
|
13 |
+
License: Free for commercial use. No attribution required.
|
14 |
+
https://pixabay.com/en/service/license/
|
15 |
+
|
16 |
+
URL:
|
17 |
+
https://pixabay.com/en/videos/star-long-exposure-starry-sky-sky-6962/
|
18 |
+
|
19 |
+
"""
|
20 |
+
)
|
pages/data.dataframe.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
@st.experimental_memo
|
6 |
+
def load_data():
|
7 |
+
df = pd.DataFrame(np.random.randn(50, 20), columns=("col %d" % i for i in range(20)))
|
8 |
+
return df
|
9 |
+
|
10 |
+
df = load_data()
|
11 |
+
|
12 |
+
st.dataframe(df) # Same as st.write(df)
|
pages/data.dataframe1.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
@st.experimental_memo
|
6 |
+
def load_data():
|
7 |
+
df = pd.DataFrame(np.random.randn(10, 20), columns=("col %d" % i for i in range(20)))
|
8 |
+
return df
|
9 |
+
|
10 |
+
df = load_data()
|
11 |
+
|
12 |
+
st.dataframe(df.style.highlight_max(axis=0))
|
pages/data.dataframe2.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
|
5 |
+
# Cache the dataframe so it's only loaded once
|
6 |
+
@st.experimental_memo
|
7 |
+
def load_data():
|
8 |
+
return pd.DataFrame(
|
9 |
+
{
|
10 |
+
"first column": [1, 2, 3, 4],
|
11 |
+
"second column": [10, 20, 30, 40],
|
12 |
+
}
|
13 |
+
)
|
14 |
+
|
15 |
+
|
16 |
+
# Boolean to resize the dataframe, stored as a session state variable
|
17 |
+
st.checkbox("Use container width", value=False, key="use_container_width")
|
18 |
+
|
19 |
+
df = load_data()
|
20 |
+
|
21 |
+
# Display the dataframe and allow the user to stretch the dataframe
|
22 |
+
# across the full width of the container
|
23 |
+
st.dataframe(df, use_container_width=st.session_state.use_container_width)
|
pages/data.json.py
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.json(
|
4 |
+
{"foo": "bar", "baz": "boz", "stuff": ["stuff 1", "stuff 2", "stuff 3", "stuff 5"]}
|
5 |
+
)
|
pages/data.table.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
@st.experimental_memo
|
6 |
+
def load_data():
|
7 |
+
df = pd.DataFrame(np.random.randn(10, 5), columns=("col %d" % i for i in range(5)))
|
8 |
+
return df
|
9 |
+
|
10 |
+
df = load_data()
|
11 |
+
|
12 |
+
st.table(df)
|
pages/flower.png
ADDED
![]() |
pages/forms.form1.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
with st.form("my_form"):
|
4 |
+
st.write("Inside the form")
|
5 |
+
slider_val = st.slider("Form slider")
|
6 |
+
checkbox_val = st.checkbox("Form checkbox")
|
7 |
+
|
8 |
+
# Every form must have a submit button.
|
9 |
+
submitted = st.form_submit_button("Submit")
|
10 |
+
if submitted:
|
11 |
+
st.write("slider", slider_val, "checkbox", checkbox_val)
|
12 |
+
|
13 |
+
st.write("Outside the form")
|
pages/forms.form2.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
form = st.form("my_form")
|
4 |
+
form.slider("Inside the form")
|
5 |
+
st.slider("Outside the form")
|
6 |
+
|
7 |
+
# Now add a submit button to the form:
|
8 |
+
form.form_submit_button("Submit")
|
pages/layout.columns1.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
col1, col2, col3 = st.columns(3)
|
4 |
+
|
5 |
+
with col1:
|
6 |
+
st.header("A cat")
|
7 |
+
st.image("https://static.streamlit.io/examples/cat.jpg")
|
8 |
+
st.markdown("By [@phonvanna](https://unsplash.com/photos/0g7BJEXq7sU)")
|
9 |
+
|
10 |
+
|
11 |
+
with col2:
|
12 |
+
st.header("A dog")
|
13 |
+
st.image("https://static.streamlit.io/examples/dog.jpg")
|
14 |
+
st.markdown("By [@shotbyrain](https://unsplash.com/photos/rmkIqi_C3cA)")
|
15 |
+
|
16 |
+
|
17 |
+
with col3:
|
18 |
+
st.header("An owl")
|
19 |
+
st.image("https://static.streamlit.io/examples/owl.jpg")
|
20 |
+
st.markdown("By [@zmachacek](https://unsplash.com/photos/ZN4CzqizIyI)")
|
pages/layout.columns2.py
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
|
4 |
+
@st.experimental_memo
|
5 |
+
def load_data():
|
6 |
+
data = np.random.randn(10, 1)
|
7 |
+
return data
|
8 |
+
|
9 |
+
col1, col2 = st.columns([3, 1])
|
10 |
+
data = load_data()
|
11 |
+
|
12 |
+
col1.subheader("A wide column with a chart")
|
13 |
+
col1.line_chart(data)
|
14 |
+
|
15 |
+
col2.subheader("A narrow column with the data")
|
16 |
+
col2.write(data)
|
pages/layout.container1.py
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
import pandas as pd
|
4 |
+
|
5 |
+
with st.container():
|
6 |
+
st.write("This is inside the container")
|
7 |
+
|
8 |
+
# You can call any Streamlit command, including custom components:
|
9 |
+
st.bar_chart(np.random.randn(50, 3))
|
10 |
+
st.write("This is outside the container")
|
pages/layout.container2.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
container = st.container()
|
4 |
+
container.write("This is inside the container")
|
5 |
+
st.write("This is outside the container")
|
6 |
+
|
7 |
+
# Now insert some more in the container
|
8 |
+
container.write("This is inside too")
|
pages/layout.expander.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.bar_chart({"d6": [1, 5, 2, 6, 2, 1]})
|
4 |
+
|
5 |
+
with st.expander("See explanation"):
|
6 |
+
st.write(
|
7 |
+
"""
|
8 |
+
The chart above shows some numbers I picked for you.
|
9 |
+
I rolled actual dice for these, so they're *guaranteed* to
|
10 |
+
be random.
|
11 |
+
"""
|
12 |
+
)
|
13 |
+
st.image("https://static.streamlit.io/examples/dice.jpg", width=200)
|
14 |
+
st.markdown("Photo by [@brett_jordon](https://unsplash.com/photos/4aB1nGtD_Sg)")
|
pages/layout.tabs1.py
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
tab1, tab2, tab3 = st.tabs(["Cat", "Dog", "Owl"])
|
4 |
+
with tab1:
|
5 |
+
st.header("A cat")
|
6 |
+
st.image("https://static.streamlit.io/examples/cat.jpg", width=200)
|
7 |
+
|
8 |
+
with tab2:
|
9 |
+
st.header("A dog")
|
10 |
+
st.image("https://static.streamlit.io/examples/dog.jpg", width=200)
|
11 |
+
|
12 |
+
with tab3:
|
13 |
+
st.header("An owl")
|
14 |
+
st.image("https://static.streamlit.io/examples/owl.jpg", width=200)
|
pages/layout.tabs2.py
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
|
4 |
+
tab1, tab2 = st.tabs(["📈 Chart", "🗃 Data"])
|
5 |
+
data = np.random.randn(10, 1)
|
6 |
+
|
7 |
+
tab1.subheader("A tab with a chart")
|
8 |
+
tab1.line_chart(data)
|
9 |
+
|
10 |
+
tab2.subheader("A tab with the data")
|
11 |
+
tab2.write(data)
|
pages/metric.example1.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.metric(label="Temperature", value="70 °F", delta="1.2 °F", delta_color="normal")
|
pages/metric.example2.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
col1, col2, col3 = st.columns(3)
|
4 |
+
col1.metric("Temperature", "70 °F", "1.2 °F")
|
5 |
+
col2.metric("Wind", "9 mph", "-8%")
|
6 |
+
col3.metric("Humidity", "86%", "4%")
|
pages/metric.example3.py
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.metric(label="Gas price", value=4, delta=-0.5, delta_color="inverse")
|
4 |
+
st.metric(label="Active developers", value=123, delta=123, delta_color="off")
|
pages/requirements.txt
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pandas==1.2.5
|
2 |
+
plotly==5.1.0
|
3 |
+
bokeh==2.4.3
|
4 |
+
graphviz==0.17
|
5 |
+
requests==2.22.0
|
6 |
+
matplotlib==3.4.1
|
7 |
+
numpy==1.22.0
|
8 |
+
scipy
|
9 |
+
altair==4.2.0
|
10 |
+
pydeck==0.7.1
|
11 |
+
streamlit==1.13.0
|
pages/text.caption.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.caption('This is a caption')
|
pages/text.code.py
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
code = """def hello():
|
4 |
+
print("Hello, Streamlit!")"""
|
5 |
+
st.code(code, language="python")
|
pages/text.header.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.header("This is a header")
|
pages/text.latex.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.latex(
|
4 |
+
r"""
|
5 |
+
a + ar + a r^2 + a r^3 + \cdots + a r^{n-1} =
|
6 |
+
\sum_{k=0}^{n-1} ar^k =
|
7 |
+
a \left(\frac{1-r^{n}}{1-r}\right)
|
8 |
+
"""
|
9 |
+
)
|
pages/text.markdown.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.markdown("Streamlit is **_really_ cool**.")
|
pages/text.subheader.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.subheader("This is a subheader")
|
pages/text.text.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.text("This is some text.")
|
pages/text.title.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.title("This is a title")
|
pages/text.write1.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.write("Hello, *World!* :sunglasses:")
|
pages/text.write2.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
st.write(1234)
|
5 |
+
st.write(
|
6 |
+
pd.DataFrame({"first column": [1, 2, 3, 4], "second column": [10, 20, 30, 40]})
|
7 |
+
)
|
pages/text.write3.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
@st.experimental_memo
|
5 |
+
def load_data():
|
6 |
+
data_frame = pd.DataFrame(
|
7 |
+
{"first column": [1, 2, 3, 4], "second column": [10, 20, 30, 40]}
|
8 |
+
)
|
9 |
+
return data_frame
|
10 |
+
|
11 |
+
data_frame = load_data()
|
12 |
+
st.write("1 + 1 = ", 2)
|
13 |
+
st.write("Below is a DataFrame:", data_frame, "Above is a dataframe.")
|
pages/widget.button.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
if st.button("Say hello"):
|
4 |
+
st.write("Why hello there")
|
5 |
+
else:
|
6 |
+
st.write("Goodbye")
|
pages/widget.checkbox.py
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
agree = st.checkbox("I agree")
|
4 |
+
if agree:
|
5 |
+
st.write("Great!")
|
pages/widget.color_picker.py
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
color = st.color_picker('Pick A Color', '#00f900')
|
4 |
+
st.write('The current color is', color)
|
pages/widget.date_input.py
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import datetime
|
3 |
+
|
4 |
+
d = st.date_input("When's your birthday", datetime.date(2020, 8, 11))
|
5 |
+
st.write("Your birthday is:", d)
|
pages/widget.download_button.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
@st.experimental_memo
|
6 |
+
def load_data():
|
7 |
+
data = pd.DataFrame(
|
8 |
+
np.random.randn(1000, 2),
|
9 |
+
columns=['a', 'b'])
|
10 |
+
|
11 |
+
return data
|
12 |
+
|
13 |
+
@st.experimental_memo
|
14 |
+
def convert_df(df):
|
15 |
+
# IMPORTANT: Cache the conversion to prevent computation on every rerun
|
16 |
+
return df.to_csv().encode('utf-8')
|
17 |
+
|
18 |
+
my_large_df = load_data()
|
19 |
+
csv = convert_df(my_large_df)
|
20 |
+
|
21 |
+
st.download_button(
|
22 |
+
label="Download data as CSV",
|
23 |
+
data=csv,
|
24 |
+
file_name='large_df.csv',
|
25 |
+
mime='text/csv',
|
26 |
+
)
|
27 |
+
|
28 |
+
text_contents = '''This is some text'''
|
29 |
+
st.download_button('Download some text', text_contents)
|
30 |
+
|
31 |
+
binary_contents = b'example content'
|
32 |
+
# Defaults to 'application/octet-stream'
|
33 |
+
st.download_button('Download binary file', binary_contents)
|
34 |
+
|
35 |
+
with open("pages/flower.png", "rb") as file:
|
36 |
+
btn = st.download_button(
|
37 |
+
label="Download image",
|
38 |
+
data=file,
|
39 |
+
file_name="flower.png",
|
40 |
+
mime="image/png"
|
41 |
+
)
|
pages/widget.file_uploader.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
uploaded_files = st.file_uploader("Choose a file", accept_multiple_files=True)
|
4 |
+
|
5 |
+
for uploaded_file in uploaded_files:
|
6 |
+
st.write("filename:", uploaded_file.name)
|