Milind Kamat commited on
Commit
65ac6c0
·
1 Parent(s): 2b772c8

2024 Dec 30 Version 01 Playground introduced

Browse files

Signed-off-by: Milind Kamat <36366961+milindkamat0507@users.noreply.github.com>

Files changed (1) hide show
  1. app.py +125 -100
app.py CHANGED
@@ -1,144 +1,169 @@
1
  import streamlit as st
2
  import pandas as pd
3
  import numpy as np
4
- from datetime import datetime
5
 
6
- # Page Configuration
7
- st.set_page_config(
8
- page_title="MBA Streamlit Tutorial",
9
- page_icon="🎓",
10
- layout="wide"
11
- )
12
 
13
- # Main Title
14
  st.title("Welcome to Streamlit Development Journey 🚀")
15
- st.markdown("*An interactive guide for MBA students*")
16
 
17
- # Sidebar
18
  with st.sidebar:
19
  st.header("Navigation Panel")
20
  page = st.radio(
21
  "Choose your learning path:",
22
- ["Basic Elements", "Data Display", "Interactive Widgets", "Charts", "Chat Interface"]
23
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
- # User Info Collection
26
- st.sidebar.markdown("---")
27
- student_name = st.text_input("Enter your name:")
28
- experience = st.select_slider(
29
- "Your coding experience:",
30
- options=["Beginner", "Intermediate", "Advanced"]
31
  )
 
 
 
 
 
 
 
 
32
 
33
- # Main Content Based on Selection
34
- if page == "Basic Elements":
35
- st.header("Basic Streamlit Elements")
36
 
37
- tab1, tab2, tab3 = st.tabs(["Text Elements", "Input Elements", "Layout Elements"])
38
 
39
- with tab1:
40
- st.subheader("Text Display Options")
41
- st.write("Regular text using st.write()")
42
- st.markdown("**Bold text** and *italic text* using markdown")
43
- st.code("""
44
- st.write("Regular text")
45
- st.markdown("**Bold text**")
46
- """)
47
-
48
- with tab2:
49
- st.subheader("Input Elements Demo")
50
- user_input = st.text_input("Try typing something:")
51
- st.write("You typed:", user_input)
52
 
53
- number = st.number_input("Enter a number:", min_value=0, max_value=100)
54
- st.write("Selected number:", number)
 
 
 
 
 
 
55
 
56
- with tab3:
57
- st.subheader("Layout Elements")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  col1, col2 = st.columns(2)
59
  with col1:
60
  st.write("This is column 1")
 
61
  with col2:
62
  st.write("This is column 2")
 
 
 
 
 
 
 
 
 
 
 
63
 
64
  elif page == "Data Display":
65
- st.header("Working with Data")
66
 
67
- # Sample DataFrame
68
  df = pd.DataFrame({
69
- 'Date': pd.date_range('2024-01-01', periods=5),
70
- 'Sales': np.random.randn(5) * 100 + 500,
71
- 'Customers': np.random.randint(50, 100, 5)
72
  })
73
 
74
- st.dataframe(df)
75
- st.code("""
76
- # Create and display a DataFrame
77
- df = pd.DataFrame({
78
- 'Date': pd.date_range('2024-01-01', periods=5),
79
- 'Sales': np.random.randn(5) * 100 + 500,
80
- 'Customers': np.random.randint(50, 100, 5)
81
- })
82
- st.dataframe(df)
83
- """)
84
-
85
- elif page == "Interactive Widgets":
86
- st.header("Interactive Elements")
87
-
88
- option = st.selectbox(
89
- 'Select your favorite color',
90
- ['Red', 'Blue', 'Green', 'Yellow']
91
- )
92
 
93
- if st.button('Show Selected Color'):
94
- st.write(f'Your selected color is {option}')
 
95
 
96
- st.slider('Select a range', 0, 100, (25, 75))
 
 
 
 
 
97
 
98
- elif page == "Charts":
99
- st.header("Data Visualization")
100
 
101
- # Generate sample data
102
  chart_data = pd.DataFrame(
103
  np.random.randn(20, 3),
104
- columns=['Line A', 'Line B', 'Line C']
105
  )
106
 
107
- st.line_chart(chart_data)
 
 
 
 
 
 
 
 
 
 
 
 
108
  st.code("""
109
- # Create a line chart
110
- chart_data = pd.DataFrame(
111
- np.random.randn(20, 3),
112
- columns=['Line A', 'Line B', 'Line C']
113
- )
114
  st.line_chart(chart_data)
 
 
115
  """)
116
 
117
- elif page == "Chat Interface":
118
- st.header("Simple Chatbot Interface")
119
-
120
- if 'messages' not in st.session_state:
121
- st.session_state.messages = []
122
-
123
- # Display chat messages
124
- for message in st.session_state.messages:
125
- with st.chat_message(message["role"]):
126
- st.markdown(message["content"])
127
-
128
- # Chat input
129
- if prompt := st.chat_input("What would you like to know about Streamlit?"):
130
- # Add user message to chat history
131
- st.session_state.messages.append({"role": "user", "content": prompt})
132
-
133
- # Simple response logic
134
- response = f"Thank you for your question about '{prompt}'. This is a demo chatbot interface in Streamlit!"
135
-
136
- # Add assistant response to chat history
137
- st.session_state.messages.append({"role": "assistant", "content": response})
138
-
139
- # Rerun to display new messages
140
- st.rerun()
141
-
142
  # Footer
143
  st.markdown("---")
144
- st.markdown("Created for MBA Students - Learning Streamlit Development")
 
1
  import streamlit as st
2
  import pandas as pd
3
  import numpy as np
 
4
 
5
+ st.set_page_config(page_title="Interactive Streamlit Tutorial", layout="wide")
 
 
 
 
 
6
 
 
7
  st.title("Welcome to Streamlit Development Journey 🚀")
8
+ st.markdown("*An interactive guide for MBA students - Practice as you learn!*")
9
 
 
10
  with st.sidebar:
11
  st.header("Navigation Panel")
12
  page = st.radio(
13
  "Choose your learning path:",
14
+ ["Text Elements", "Input Widgets", "Layout & Containers", "Data Display", "Interactive Charts"]
15
  )
16
+
17
+ if page == "Text Elements":
18
+ st.header("1. Text Elements Playground")
19
+
20
+ # Learning Section
21
+ st.subheader("📚 Learn")
22
+ with st.expander("See text formatting examples"):
23
+ st.code("""
24
+ # Different ways to display text:
25
+ st.write('Regular text')
26
+ st.markdown('**Bold** and *italic*')
27
+ st.title('Main Title')
28
+ st.header('Header')
29
+ st.subheader('Subheader')
30
+ st.code('print("Hello World")')
31
+ """)
32
+
33
+ # Practice Section
34
+ st.subheader("🔨 Practice")
35
+ st.write("Try these text elements yourself!")
36
 
37
+ code_input = st.text_area(
38
+ "Type your Streamlit code here:",
39
+ height=100,
40
+ placeholder="Example: st.write('Hello World')"
 
 
41
  )
42
+
43
+ if st.button("Run Code"):
44
+ try:
45
+ with st.container():
46
+ st.write("Your Output:")
47
+ exec(code_input)
48
+ except Exception as e:
49
+ st.error(f"Error: {str(e)}")
50
 
51
+ elif page == "Input Widgets":
52
+ st.header("2. Input Widgets Laboratory")
 
53
 
54
+ col1, col2 = st.columns(2)
55
 
56
+ with col1:
57
+ st.subheader("Widget Examples")
58
+ st.write("Try these interactive widgets:")
 
 
 
 
 
 
 
 
 
 
59
 
60
+ # Text input
61
+ name = st.text_input("Enter your name:")
62
+ if name:
63
+ st.write(f"Hello, {name}!")
64
+
65
+ # Number input
66
+ number = st.number_input("Pick a number", 0, 100)
67
+ st.write(f"Your number squared is: {number**2}")
68
 
69
+ # Slider
70
+ age = st.slider("Select your age", 0, 100, 25)
71
+ st.write(f"You selected: {age} years")
72
+
73
+ with col2:
74
+ st.subheader("Code Reference")
75
+ st.code("""
76
+ # Text input
77
+ name = st.text_input("Enter your name:")
78
+ if name:
79
+ st.write(f"Hello, {name}!")
80
+
81
+ # Number input
82
+ number = st.number_input("Pick a number", 0, 100)
83
+
84
+ # Slider
85
+ age = st.slider("Select your age", 0, 100, 25)
86
+ """)
87
+
88
+ elif page == "Layout & Containers":
89
+ st.header("3. Layout Workshop")
90
+
91
+ st.write("Experiment with different layouts:")
92
+
93
+ tab1, tab2, tab3 = st.tabs(["Columns", "Expander", "Container"])
94
+
95
+ with tab1:
96
+ st.write("Create two columns:")
97
  col1, col2 = st.columns(2)
98
  with col1:
99
  st.write("This is column 1")
100
+ st.button("Column 1 Button")
101
  with col2:
102
  st.write("This is column 2")
103
+ st.button("Column 2 Button")
104
+
105
+ with tab2:
106
+ with st.expander("Click to expand"):
107
+ st.write("This content is hidden until expanded!")
108
+ st.slider("Hidden slider", 0, 100)
109
+
110
+ with tab3:
111
+ with st.container():
112
+ st.write("This is a container")
113
+ st.metric(label="Temperature", value="24 °C", delta="1.2 °C")
114
 
115
  elif page == "Data Display":
116
+ st.header("4. Data Display Workshop")
117
 
118
+ # Create sample data
119
  df = pd.DataFrame({
120
+ 'Name': ['John', 'Emma', 'Alex', 'Sarah'],
121
+ 'Age': [28, 24, 32, 27],
122
+ 'City': ['New York', 'London', 'Paris', 'Tokyo']
123
  })
124
 
125
+ st.subheader("Practice with DataFrames")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
 
127
+ # Show data manipulation options
128
+ st.write("Original DataFrame:")
129
+ st.dataframe(df)
130
 
131
+ # Let users try filtering
132
+ city_filter = st.selectbox("Filter by city:", ['All'] + list(df['City'].unique()))
133
+ if city_filter != 'All':
134
+ filtered_df = df[df['City'] == city_filter]
135
+ st.write("Filtered DataFrame:")
136
+ st.dataframe(filtered_df)
137
 
138
+ elif page == "Interactive Charts":
139
+ st.header("5. Visualization Lab")
140
 
141
+ # Generate random data
142
  chart_data = pd.DataFrame(
143
  np.random.randn(20, 3),
144
+ columns=['A', 'B', 'C']
145
  )
146
 
147
+ # Let users choose chart type
148
+ chart_type = st.selectbox(
149
+ "Select chart type:",
150
+ ["Line Chart", "Bar Chart", "Area Chart"]
151
+ )
152
+
153
+ if chart_type == "Line Chart":
154
+ st.line_chart(chart_data)
155
+ elif chart_type == "Bar Chart":
156
+ st.bar_chart(chart_data)
157
+ else:
158
+ st.area_chart(chart_data)
159
+
160
  st.code("""
161
+ # Create charts
 
 
 
 
162
  st.line_chart(chart_data)
163
+ st.bar_chart(chart_data)
164
+ st.area_chart(chart_data)
165
  """)
166
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  # Footer
168
  st.markdown("---")
169
+ st.markdown("💡 **Pro Tip:** Try modifying the code examples to see how they change the output!")