Milind Kamat commited on
Commit
b225e2a
Β·
1 Parent(s): 4d2f949

2024 Dec 30 new playground added

Browse files

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

Files changed (1) hide show
  1. app.py +77 -96
app.py CHANGED
@@ -13,117 +13,98 @@ with st.sidebar:
13
  "Layouts & Containers",
14
  "Data Display",
15
  "Charts & Plots",
16
- "Interactive Components",
17
- "Playground"
18
  ]
19
  )
20
 
21
  if selected_topic == "Basic Text Elements":
22
  st.title("Basic Text Elements in Streamlit")
23
-
24
- # Create two equal columns
25
- col1, col2 = st.columns(2)
26
-
27
- with col1:
28
- st.markdown("### πŸ“ Code Examples")
29
- # Code section with comments
30
- st.markdown("#### Title")
31
- st.code("st.title('Main Title')")
32
- st.markdown("↳") # Arrow pointing to output
33
-
34
- st.markdown("#### Header")
35
- st.code("st.header('Header')")
36
- st.markdown("↳")
37
-
38
- st.markdown("#### Subheader")
39
- st.code("st.subheader('Subheader')")
40
- st.markdown("↳")
41
-
42
- st.markdown("#### Normal text")
43
- st.code("st.write('Normal text')")
44
- st.markdown("↳")
45
-
46
- st.markdown("#### Markdown text")
47
- st.code("st.markdown('**Bold** and *italic*')")
48
- st.markdown("↳")
49
-
50
- st.markdown("#### Colored text")
51
- st.code("st.markdown(':blue[Blue text]')")
52
- st.markdown("↳")
53
 
54
- with col2:
55
- st.markdown("### 🎯 Live Output")
56
- st.title('Main Title')
57
- st.markdown("---") # Separator
58
-
59
- st.header('Header')
60
- st.markdown("---")
61
-
62
- st.subheader('Subheader')
63
- st.markdown("---")
64
-
65
- st.write('Normal text')
66
- st.markdown("---")
67
 
68
- st.markdown('**Bold** and *italic*')
69
- st.markdown("---")
70
 
71
- st.markdown(':blue[Blue text]')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
- elif selected_topic == "Playground":
74
- st.title("πŸ’» Streamlit Playground")
75
-
76
- # Split screen for code and output
77
- col1, col2 = st.columns([1, 1])
78
-
79
- with col1:
80
- st.markdown("### ✍️ Write Your Code")
81
- code = st.text_area(
82
- "Try Streamlit commands here:",
83
- height=400,
84
- placeholder="""Examples to try:
85
 
86
- st.title('My Title')
87
- st.write('Hello World!')
88
- st.markdown('**Bold** and *italic*')
89
- st.markdown(':blue[Colored text]')
90
- """
91
- )
92
-
93
- # Add helpful snippets
94
- st.markdown("#### πŸ“š Quick Snippets")
95
- snippets = {
96
- "Title": "st.title('My Title')",
97
- "Header": "st.header('My Header')",
98
- "Colored Text": "st.markdown(':blue[Blue text]')",
99
- "Bold & Italic": "st.markdown('**Bold** and *italic*')",
100
- }
101
 
102
- selected_snippet = st.selectbox("Insert a snippet:", list(snippets.keys()))
103
- if st.button("Insert Snippet"):
104
- if code:
105
- code += "\n" + snippets[selected_snippet]
106
- else:
107
- code = snippets[selected_snippet]
108
-
109
- with col2:
110
- st.markdown("### 🎯 Live Output")
111
  with st.container(border=True):
112
- if code:
113
- try:
114
- exec(code)
115
- except Exception as e:
116
- st.error(f"Error: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
 
118
- # Tips & Documentation
119
  with st.expander("πŸ’‘ Tips & Tricks"):
120
  st.markdown("""
121
- ### Helpful Tips:
122
- - Start with basic text elements (`st.write`, `st.markdown`)
123
- - Use markdown for formatting (`**bold**`, `*italic*`)
124
- - Try colored text with `:blue[text]`, `:red[text]`, etc.
125
- - Experiment with different header levels
126
- - Watch the live output as you type
127
  """)
128
 
129
  st.markdown("---")
 
13
  "Layouts & Containers",
14
  "Data Display",
15
  "Charts & Plots",
16
+ "Interactive Components"
 
17
  ]
18
  )
19
 
20
  if selected_topic == "Basic Text Elements":
21
  st.title("Basic Text Elements in Streamlit")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
+ # Create two main sections: Learning and Practice
24
+ learning_col, practice_col = st.columns([1.2, 0.8])
25
+
26
+ # Learning Section (Code Examples + Live Output)
27
+ with learning_col:
28
+ st.markdown("### πŸ“š Learning Section")
 
 
 
 
 
 
 
29
 
30
+ # Create two sub-columns for code and output
31
+ code_col, output_col = st.columns(2)
32
 
33
+ with code_col:
34
+ st.markdown("#### πŸ“ Code Examples")
35
+
36
+ st.markdown("**Title**")
37
+ st.code("st.title('Main Title')")
38
+
39
+ st.markdown("**Header**")
40
+ st.code("st.header('Header')")
41
+
42
+ st.markdown("**Subheader**")
43
+ st.code("st.subheader('Subheader')")
44
+
45
+ st.markdown("**Normal text**")
46
+ st.code("st.write('Normal text')")
47
+
48
+ st.markdown("**Markdown text**")
49
+ st.code("st.markdown('**Bold** and *italic*')")
50
+
51
+ st.markdown("**Colored text**")
52
+ st.code("st.markdown(':blue[Blue text]')")
53
 
54
+ with output_col:
55
+ st.markdown("#### 🎯 Live Output")
56
+ with st.container(border=True):
57
+ st.title('Main Title')
58
+ st.header('Header')
59
+ st.subheader('Subheader')
60
+ st.write('Normal text')
61
+ st.markdown('**Bold** and *italic*')
62
+ st.markdown(':blue[Blue text]')
 
 
 
63
 
64
+ # Practice Section (Playground)
65
+ with practice_col:
66
+ st.markdown("### πŸ’» Practice Playground")
 
 
 
 
 
 
 
 
 
 
 
 
67
 
 
 
 
 
 
 
 
 
 
68
  with st.container(border=True):
69
+ code = st.text_area(
70
+ "Try Streamlit commands:",
71
+ height=200,
72
+ placeholder="Example:\nst.title('My Title')"
73
+ )
74
+
75
+ st.markdown("#### Quick Snippets")
76
+ snippets = {
77
+ "Title": "st.title('My Title')",
78
+ "Header": "st.header('My Header')",
79
+ "Colored Text": "st.markdown(':blue[Blue text]')",
80
+ "Bold & Italic": "st.markdown('**Bold** and *italic*')",
81
+ }
82
+
83
+ col1, col2 = st.columns([2, 1])
84
+ with col1:
85
+ selected_snippet = st.selectbox("Insert:", list(snippets.keys()))
86
+ with col2:
87
+ if st.button("Add Snippet"):
88
+ if code:
89
+ code += "\n" + snippets[selected_snippet]
90
+ else:
91
+ code = snippets[selected_snippet]
92
+
93
+ st.markdown("#### Output")
94
+ with st.container(border=True):
95
+ if code:
96
+ try:
97
+ exec(code)
98
+ except Exception as e:
99
+ st.error(f"Error: {str(e)}")
100
 
101
+ # Tips Section
102
  with st.expander("πŸ’‘ Tips & Tricks"):
103
  st.markdown("""
104
+ - Use `st.write()` for simple text output
105
+ - Use markdown for formatted text
106
+ - Try different header levels (title, header, subheader)
107
+ - Experiment with colored text using `:blue[text]`, `:red[text]`, etc.
 
 
108
  """)
109
 
110
  st.markdown("---")