nprime commited on
Commit
fcfe439
Β·
verified Β·
1 Parent(s): 9c56e90

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +94 -38
src/streamlit_app.py CHANGED
@@ -1,40 +1,96 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- """
7
- # Welcome to Streamlit!
8
-
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
-
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
1
  import streamlit as st
2
+ import time
3
+
4
+ # --- Page Configuration ---
5
+ # This should be the first Streamlit command in your app
6
+ st.set_page_config(
7
+ page_title="Streamlit Basics",
8
+ page_icon="🎈",
9
+ layout="wide",
10
+ )
11
+
12
+ # --- Sidebar ---
13
+ # You can add widgets to the sidebar using `st.sidebar.`
14
+ st.sidebar.title("App Controls")
15
+ st.sidebar.markdown("Use these widgets to see the app update!")
16
+
17
+ # WIDGET 1: Checkbox (Boolean)
18
+ show_balloons = st.sidebar.checkbox("Show balloons on button click?", value=True)
19
+
20
+ # WIDGET 2: Slider (Number)
21
+ number_of_items = st.sidebar.slider(
22
+ "How many items?",
23
+ min_value=1,
24
+ max_value=10,
25
+ value=5
26
+ )
27
+
28
+ # --- Main Page Content ---
29
+ st.title("Welcome to Streamlit Basics! 🎈")
30
+ st.markdown(
31
+ """
32
+ This is a super simple app to show you how Streamlit works.
33
+ Notice how the app reruns from top to bottom every time you
34
+ interact with a widget in the sidebar.
35
+ """
36
+ )
37
+ st.divider()
38
+
39
+ # --- Section 1: Text Input ---
40
+ st.header("1. Text Input")
41
+ st.markdown("Whatever you type here is stored in a Python variable.")
42
+
43
+ # WIDGET 3: Text Input
44
+ user_name = st.text_input("What's your name?", "Streamlit User")
45
+
46
+ # The app's output reacts to the widget's current value
47
+ st.write(f"Hello, **{user_name}**!")
48
+ st.divider()
49
+
50
+ # --- Section 2: Using Widget Values ---
51
+ st.header("2. Using Widget Values")
52
+ st.markdown("Here, we use the values from the sidebar widgets.")
53
+
54
+ st.write(f"You've selected **{number_of_items}** items.")
55
+
56
+ # We can use standard Python `if` statements
57
+ if show_balloons:
58
+ st.write("The 'Show balloons' checkbox is **checked**! πŸ‘")
59
+ else:
60
+ st.write("The 'Show balloons' checkbox is **unchecked**. πŸ‘Ž")
61
+ st.divider()
62
+
63
+ # --- Section 3: Buttons and State ---
64
+ st.header("3. Buttons")
65
+ st.markdown(
66
+ """
67
+ Buttons are special. They are 'event' widgets.
68
+ They are only `True` for the *single rerun* right after they are clicked.
69
+ """
70
+ )
71
+
72
+ # WIDGET 4: Button
73
+ if st.button("Click me!", type="primary"):
74
+ # This block of code only runs when the button is clicked
75
+ st.success(f"You clicked the button, {user_name}!")
76
+
77
+ # Let's use the checkbox value
78
+ if show_balloons:
79
+ st.balloons()
80
+
81
+ # Buttons can also trigger longer processes
82
+ st.write("Running a 'long' process...")
83
+
84
+ # A progress bar
85
+ progress_bar = st.progress(0, text="Starting...")
86
+
87
+ for i in range(100):
88
+ time.sleep(0.01) # Simulate some work
89
+ progress_bar.progress(i + 1, text=f"Processing item {i+1}")
90
+
91
+ progress_bar.empty() # Clear the progress bar
92
+ st.write("Done!")
93
+ else:
94
+ # This shows when the button hasn't just been clicked
95
+ st.info("Click the button to see what happens.")
96