Skip to content

Commit cc7974f

Browse files
authored
Initial commit
0 parents  commit cc7974f

File tree

11 files changed

+472
-0
lines changed

11 files changed

+472
-0
lines changed

.devcontainer/devcontainer.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "Python 3",
3+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
4+
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bullseye",
5+
"customizations": {
6+
"codespaces": {
7+
"openFiles": [
8+
"README.md",
9+
"Hello.py"
10+
]
11+
},
12+
"vscode": {
13+
"settings": {},
14+
"extensions": [
15+
"ms-python.python",
16+
"ms-python.vscode-pylance"
17+
]
18+
}
19+
},
20+
"updateContentCommand": "[ -f packages.txt ] && sudo apt update && sudo apt upgrade -y && sudo xargs apt install -y <packages.txt; [ -f requirements.txt ] && pip3 install --user -r requirements.txt; pip3 install --user streamlit; echo '✅ Packages installed and Requirements met'",
21+
"postAttachCommand": {
22+
"server": "streamlit run Hello.py --server.enableCORS false --server.enableXsrfProtection false"
23+
},
24+
"portsAttributes": {
25+
"8501": {
26+
"label": "Application",
27+
"onAutoForward": "openPreview"
28+
}
29+
},
30+
"forwardPorts": [
31+
8501
32+
]
33+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.streamlit/

Hello.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import streamlit as st
16+
from streamlit.logger import get_logger
17+
18+
LOGGER = get_logger(__name__)
19+
20+
21+
def run():
22+
st.set_page_config(
23+
page_title="Hello",
24+
page_icon="👋",
25+
)
26+
27+
st.write("# Welcome to Streamlit! 👋")
28+
29+
st.sidebar.success("Select a demo above.")
30+
31+
st.markdown(
32+
"""
33+
Streamlit is an open-source app framework built specifically for
34+
Machine Learning and Data Science projects.
35+
**👈 Select a demo from the sidebar** to see some examples
36+
of what Streamlit can do!
37+
### Want to learn more?
38+
- Check out [streamlit.io](https://streamlit.io)
39+
- Jump into our [documentation](https://docs.streamlit.io)
40+
- Ask a question in our [community
41+
forums](https://discuss.streamlit.io)
42+
### See more complex demos
43+
- Use a neural net to [analyze the Udacity Self-driving Car Image
44+
Dataset](https://github.com/streamlit/demo-self-driving)
45+
- Explore a [New York City rideshare dataset](https://github.com/streamlit/demo-uber-nyc-pickups)
46+
"""
47+
)
48+
49+
50+
if __name__ == "__main__":
51+
run()

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Welcome to streamlit
2+
3+
This is the app you get when you run `streamlit hello`, extracted as its own app.
4+
5+
Edit [Hello.py](./Hello.py) to customize this app to your heart's desire. ❤️
6+
7+
Check it out on [Streamlit Community Cloud](https://st-hello-app.streamlit.app/)

__init__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.

pages/0_Animation_Demo.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from typing import Any
16+
17+
import numpy as np
18+
19+
import streamlit as st
20+
from streamlit.hello.utils import show_code
21+
22+
23+
def animation_demo() -> None:
24+
25+
# Interactive Streamlit elements, like these sliders, return their value.
26+
# This gives you an extremely simple interaction model.
27+
iterations = st.sidebar.slider("Level of detail", 2, 20, 10, 1)
28+
separation = st.sidebar.slider("Separation", 0.7, 2.0, 0.7885)
29+
30+
# Non-interactive elements return a placeholder to their location
31+
# in the app. Here we're storing progress_bar to update it later.
32+
progress_bar = st.sidebar.progress(0)
33+
34+
# These two elements will be filled in later, so we create a placeholder
35+
# for them using st.empty()
36+
frame_text = st.sidebar.empty()
37+
image = st.empty()
38+
39+
m, n, s = 960, 640, 400
40+
x = np.linspace(-m / s, m / s, num=m).reshape((1, m))
41+
y = np.linspace(-n / s, n / s, num=n).reshape((n, 1))
42+
43+
for frame_num, a in enumerate(np.linspace(0.0, 4 * np.pi, 100)):
44+
# Here were setting value for these two elements.
45+
progress_bar.progress(frame_num)
46+
frame_text.text("Frame %i/100" % (frame_num + 1))
47+
48+
# Performing some fractal wizardry.
49+
c = separation * np.exp(1j * a)
50+
Z = np.tile(x, (n, 1)) + 1j * np.tile(y, (1, m))
51+
C = np.full((n, m), c)
52+
M: Any = np.full((n, m), True, dtype=bool)
53+
N = np.zeros((n, m))
54+
55+
for i in range(iterations):
56+
Z[M] = Z[M] * Z[M] + C[M]
57+
M[np.abs(Z) > 2] = False
58+
N[M] = i
59+
60+
# Update the image placeholder by calling the image() function on it.
61+
image.image(1.0 - (N / N.max()), use_column_width=True)
62+
63+
# We clear elements by calling empty on them.
64+
progress_bar.empty()
65+
frame_text.empty()
66+
67+
# Streamlit widgets automatically run the script from top to bottom. Since
68+
# this button is not connected to any other logic, it just causes a plain
69+
# rerun.
70+
st.button("Re-run")
71+
72+
73+
st.set_page_config(page_title="Animation Demo", page_icon="📹")
74+
st.markdown("# Animation Demo")
75+
st.sidebar.header("Animation Demo")
76+
st.write(
77+
"""This app shows how you can use Streamlit to build cool animations.
78+
It displays an animated fractal based on the the Julia Set. Use the slider
79+
to tune different parameters."""
80+
)
81+
82+
animation_demo()
83+
84+
show_code(animation_demo)

pages/1_Plotting_Demo.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import time
16+
17+
import numpy as np
18+
19+
import streamlit as st
20+
from streamlit.hello.utils import show_code
21+
22+
23+
def plotting_demo():
24+
progress_bar = st.sidebar.progress(0)
25+
status_text = st.sidebar.empty()
26+
last_rows = np.random.randn(1, 1)
27+
chart = st.line_chart(last_rows)
28+
29+
for i in range(1, 101):
30+
new_rows = last_rows[-1, :] + np.random.randn(5, 1).cumsum(axis=0)
31+
status_text.text("%i%% Complete" % i)
32+
chart.add_rows(new_rows)
33+
progress_bar.progress(i)
34+
last_rows = new_rows
35+
time.sleep(0.05)
36+
37+
progress_bar.empty()
38+
39+
# Streamlit widgets automatically run the script from top to bottom. Since
40+
# this button is not connected to any other logic, it just causes a plain
41+
# rerun.
42+
st.button("Re-run")
43+
44+
45+
st.set_page_config(page_title="Plotting Demo", page_icon="📈")
46+
st.markdown("# Plotting Demo")
47+
st.sidebar.header("Plotting Demo")
48+
st.write(
49+
"""This demo illustrates a combination of plotting and animation with
50+
Streamlit. We're generating a bunch of random numbers in a loop for around
51+
5 seconds. Enjoy!"""
52+
)
53+
54+
plotting_demo()
55+
56+
show_code(plotting_demo)

pages/2_Mapping_Demo.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022)
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from urllib.error import URLError
16+
17+
import pandas as pd
18+
import pydeck as pdk
19+
20+
import streamlit as st
21+
from streamlit.hello.utils import show_code
22+
23+
24+
def mapping_demo():
25+
@st.cache_data
26+
def from_data_file(filename):
27+
url = (
28+
"https://raw.githubusercontent.com/streamlit/"
29+
"example-data/master/hello/v1/%s" % filename
30+
)
31+
return pd.read_json(url)
32+
33+
try:
34+
ALL_LAYERS = {
35+
"Bike Rentals": pdk.Layer(
36+
"HexagonLayer",
37+
data=from_data_file("bike_rental_stats.json"),
38+
get_position=["lon", "lat"],
39+
radius=200,
40+
elevation_scale=4,
41+
elevation_range=[0, 1000],
42+
extruded=True,
43+
),
44+
"Bart Stop Exits": pdk.Layer(
45+
"ScatterplotLayer",
46+
data=from_data_file("bart_stop_stats.json"),
47+
get_position=["lon", "lat"],
48+
get_color=[200, 30, 0, 160],
49+
get_radius="[exits]",
50+
radius_scale=0.05,
51+
),
52+
"Bart Stop Names": pdk.Layer(
53+
"TextLayer",
54+
data=from_data_file("bart_stop_stats.json"),
55+
get_position=["lon", "lat"],
56+
get_text="name",
57+
get_color=[0, 0, 0, 200],
58+
get_size=10,
59+
get_alignment_baseline="'bottom'",
60+
),
61+
"Outbound Flow": pdk.Layer(
62+
"ArcLayer",
63+
data=from_data_file("bart_path_stats.json"),
64+
get_source_position=["lon", "lat"],
65+
get_target_position=["lon2", "lat2"],
66+
get_source_color=[200, 30, 0, 160],
67+
get_target_color=[200, 30, 0, 160],
68+
auto_highlight=True,
69+
width_scale=0.0001,
70+
get_width="outbound",
71+
width_min_pixels=3,
72+
width_max_pixels=30,
73+
),
74+
}
75+
st.sidebar.markdown("### Map Layers")
76+
selected_layers = [
77+
layer
78+
for layer_name, layer in ALL_LAYERS.items()
79+
if st.sidebar.checkbox(layer_name, True)
80+
]
81+
if selected_layers:
82+
st.pydeck_chart(
83+
pdk.Deck(
84+
map_style=None,
85+
initial_view_state={
86+
"latitude": 37.76,
87+
"longitude": -122.4,
88+
"zoom": 11,
89+
"pitch": 50,
90+
},
91+
layers=selected_layers,
92+
)
93+
)
94+
else:
95+
st.error("Please choose at least one layer above.")
96+
except URLError as e:
97+
st.error(
98+
"""
99+
**This demo requires internet access.**
100+
Connection error: %s
101+
"""
102+
% e.reason
103+
)
104+
105+
106+
st.set_page_config(page_title="Mapping Demo", page_icon="🌍")
107+
st.markdown("# Mapping Demo")
108+
st.sidebar.header("Mapping Demo")
109+
st.write(
110+
"""This demo shows how to use
111+
[`st.pydeck_chart`](https://docs.streamlit.io/library/api-reference/charts/st.pydeck_chart)
112+
to display geospatial data."""
113+
)
114+
115+
mapping_demo()
116+
117+
show_code(mapping_demo)

0 commit comments

Comments
 (0)