jnaiman commited on
Commit
3ddfd7a
1 Parent(s): 51d9500
Files changed (3) hide show
  1. app.py +65 -155
  2. requirements.txt +3 -8
  3. requirements.txt_old +8 -0
app.py CHANGED
@@ -1,161 +1,71 @@
1
- import streamlit as st
2
- import pandas as pd
3
- import numpy as np
4
- import altair as alt
5
- import plotly.express as px
6
- import plotly.graph_objects as go
7
- import pydeck as pdk
8
- from PIL import Image
9
- import cv2
10
- import io
11
-
12
- st.set_page_config(page_title="Streamlit Comprehensive Demo 🚀", page_icon="📝", layout="wide")
13
 
14
- def main():
15
- st.title("🎨 Streamlit Comprehensive Showcase")
16
- st.markdown("Explore the various features of Streamlit in this interactive demo!")
17
 
18
- # Sidebar for navigation
19
- demo_type = st.sidebar.selectbox(
20
- "Choose a Demo",
21
- ["Basic Elements", "Data Visualization", "Interactive Widgets", "Advanced Features"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- if demo_type == "Basic Elements":
25
- show_basic_elements()
26
- elif demo_type == "Data Visualization":
27
- show_data_visualization()
28
- elif demo_type == "Interactive Widgets":
29
- show_interactive_widgets()
30
- elif demo_type == "Advanced Features":
31
- show_advanced_features()
32
-
33
- def show_basic_elements():
34
- st.header("1. Basic Elements")
35
-
36
- st.subheader("1.1 Text Elements")
37
- st.text("This is simple text")
38
- st.markdown("This is **markdown** with _styling_")
39
- st.latex(r"\begin{pmatrix}a & b \\ c & d\end{pmatrix}")
40
-
41
- st.subheader("1.2 Data Display")
42
- df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
43
- st.dataframe(df)
44
- st.table(df)
45
- st.json({"foo": "bar", "baz": "boz"})
46
-
47
- st.subheader("1.3 Media Elements")
48
- st.image("https://streamlit.io/images/brand/streamlit-mark-color.png", width=200)
49
- st.audio("https://upload.wikimedia.org/wikipedia/commons/c/c4/Muriel-Nguyen-Xuan-Chopin-valse-opus64-1.ogg")
50
- st.video("https://youtu.be/B2iAodr0fOo")
51
-
52
- def show_data_visualization():
53
- st.header("2. Data Visualization")
54
-
55
- @st.cache_data
56
- def load_data():
57
- return pd.DataFrame(np.random.randn(20, 3), columns=["A", "B", "C"])
58
-
59
- data = load_data()
60
-
61
- st.subheader("2.1 Streamlit Charts")
62
- st.line_chart(data)
63
- st.area_chart(data)
64
- st.bar_chart(data)
65
-
66
- st.subheader("2.2 Altair Chart")
67
- chart = alt.Chart(data).mark_circle().encode(
68
- x='A', y='B', size='C', color='C', tooltip=['A', 'B', 'C'])
69
- st.altair_chart(chart, use_container_width=True)
70
-
71
- st.subheader("2.3 Plotly Chart")
72
- fig = px.scatter(data, x="A", y="B", size="C", color="C")
73
- st.plotly_chart(fig, use_container_width=True)
74
-
75
- st.subheader("2.4 PyDeck Chart")
76
- chart_data = pd.DataFrame(np.random.randn(1000, 2) / [50, 50] + [37.76, -122.4], columns=['lat', 'lon'])
77
- st.pydeck_chart(pdk.Deck(
78
- map_style=None,
79
- initial_view_state=pdk.ViewState(latitude=37.76, longitude=-122.4, zoom=11, pitch=50),
80
- layers=[pdk.Layer('HexagonLayer', data=chart_data, get_position='[lon, lat]', radius=200, elevation_scale=4, elevation_range=[0, 1000], pickable=True, extruded=True)]
81
- ))
82
-
83
- def show_interactive_widgets():
84
- st.header("3. Interactive Widgets")
85
-
86
- st.subheader("3.1 Input Widgets")
87
- text_input = st.text_input("Enter some text")
88
- number = st.number_input("Enter a number", min_value=0, max_value=100)
89
- date = st.date_input("Pick a date")
90
-
91
- st.subheader("3.2 Selection Widgets")
92
- option = st.selectbox("Choose an option", ["Option 1", "Option 2", "Option 3"])
93
- options = st.multiselect("Choose multiple options", ["A", "B", "C", "D"])
94
- slider_val = st.slider("Pick a number", 0, 100)
95
-
96
- st.subheader("3.3 Button and Download")
97
- if st.button("Click me!"):
98
- st.write("Button clicked!")
99
-
100
- @st.cache_data
101
- def get_sample_data():
102
- return pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
103
-
104
- csv = get_sample_data().to_csv(index=False)
105
- st.download_button("Download CSV", csv, "sample_data.csv", "text/csv")
106
-
107
- def show_advanced_features():
108
- st.header("4. Advanced Features")
109
-
110
- st.subheader("4.1 Layouts")
111
- col1, col2 = st.columns(2)
112
- with col1:
113
- st.write("This is column 1")
114
- with col2:
115
- st.write("This is column 2")
116
-
117
- with st.expander("Click to expand"):
118
- st.write("This content is hidden by default")
119
-
120
- st.subheader("4.2 Progress and Status")
121
- progress_bar = st.progress(0)
122
- for i in range(100):
123
- progress_bar.progress(i + 1)
124
- st.success("This is a success message!")
125
- st.error("This is an error message!")
126
- st.warning("This is a warning message!")
127
- st.info("This is an info message!")
128
-
129
- st.subheader("4.3 Cache and Performance")
130
- @st.cache_data
131
- def expensive_computation(a, b):
132
- return a * b
133
-
134
- result = expensive_computation(2, 21)
135
- st.write(f"2 * 21 is {result}")
136
-
137
- st.subheader("4.4 Session State")
138
- if 'count' not in st.session_state:
139
- st.session_state.count = 0
140
-
141
- if st.button('Increment'):
142
- st.session_state.count += 1
143
-
144
- st.write('Count = ', st.session_state.count)
145
-
146
- st.subheader("4.5 Forms")
147
- with st.form("my_form"):
148
- st.write("Inside the form")
149
- slider_val = st.slider("Form slider")
150
- checkbox_val = st.checkbox("Form checkbox")
151
- submitted = st.form_submit_button("Submit")
152
- if submitted:
153
- st.write("Slider", slider_val, "Checkbox", checkbox_val)
154
 
155
- st.subheader("4.6 Popover")
156
- with st.popover("Click for Popover"):
157
- st.write("This is a popover")
158
- st.image("https://streamlit.io/images/brand/streamlit-mark-color.png", width=100)
159
 
160
- if __name__ == "__main__":
161
- main()
 
 
 
1
+ # INSTRUCTIONS:
2
+ # 1. Open a "Terminal" by: View --> Terminal OR just the "Terminal" through the hamburger menu
3
+ # 2. run in terminal with: streamlit run test_altair_streamlit.py
4
+ # 3. click the "Open in Browser" link that pops up OR click on "Ports" and copy the URL
5
+ # 4. Open a Simple Browswer with View --> Command Palette --> Simple Browser: Show
6
+ # 5. use the URL from prior steps as intput into this simple browser
 
 
 
 
 
 
7
 
 
 
 
8
 
9
+ import streamlit as st
10
+ import altair as alt
11
+ from vega_datasets import data
12
+
13
+ st.title('My First Streamlit App')
14
+
15
+ source = data.seattle_weather()
16
+
17
+ scale = alt.Scale(
18
+ domain=["sun", "fog", "drizzle", "rain", "snow"],
19
+ range=["#e7ba52", "#a7a7a7", "#aec7e8", "#1f77b4", "#9467bd"],
20
+ )
21
+ color = alt.Color("weather:N", scale=scale)
22
+
23
+ # We create two selections:
24
+ # - a brush that is active on the top panel
25
+ # - a multi-click that is active on the bottom panel
26
+ brush = alt.selection_interval(encodings=["x"])
27
+ click = alt.selection_point(encodings=["color"])
28
+
29
+ # Top panel is scatter plot of temperature vs time
30
+ points = (
31
+ alt.Chart()
32
+ .mark_point()
33
+ .encode(
34
+ alt.X("monthdate(date):T", title="Date"),
35
+ alt.Y(
36
+ "temp_max:Q",
37
+ title="Maximum Daily Temperature (C)",
38
+ scale=alt.Scale(domain=[-5, 40]),
39
+ ),
40
+ color=alt.condition(brush, color, alt.value("lightgray")),
41
+ size=alt.Size("precipitation:Q", scale=alt.Scale(range=[5, 200])),
42
  )
43
+ .properties(width=550, height=300)
44
+ .add_params(brush)
45
+ .transform_filter(click)
46
+ )
47
+
48
+ # Bottom panel is a bar chart of weather type
49
+ bars = (
50
+ alt.Chart()
51
+ .mark_bar()
52
+ .encode(
53
+ x="count()",
54
+ y="weather:N",
55
+ color=alt.condition(click, color, alt.value("lightgray")),
56
+ )
57
+ .transform_filter(brush)
58
+ .properties(
59
+ width=550,
60
+ )
61
+ .add_params(click)
62
+ )
63
 
64
+ chart = alt.vconcat(points, bars, data=source, title="Seattle Weather: 2012-2015")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
+ tab1, tab2 = st.tabs(["Streamlit theme (default)", "Altair native theme"])
 
 
 
67
 
68
+ with tab1:
69
+ st.altair_chart(chart, theme="streamlit", use_container_width=True)
70
+ with tab2:
71
+ st.altair_chart(chart, theme=None, use_container_width=True)
requirements.txt CHANGED
@@ -1,8 +1,3 @@
1
- streamlit==1.36.0
2
- pandas==1.5.3
3
- numpy==1.23.5
4
- altair==5.0.1
5
- plotly==5.14.1
6
- pydeck==0.8.0
7
- Pillow==9.5.0
8
- opencv-python-headless==4.7.0.72
 
1
+ streamlit
2
+ altair
3
+ vega_datasets
 
 
 
 
 
requirements.txt_old ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ streamlit==1.36.0
2
+ pandas==1.5.3
3
+ numpy==1.23.5
4
+ altair==5.0.1
5
+ plotly==5.14.1
6
+ pydeck==0.8.0
7
+ Pillow==9.5.0
8
+ opencv-python-headless==4.7.0.72