Spaces:
Sleeping
Sleeping
Milind Kamat
commited on
Commit
Β·
b225e2a
1
Parent(s):
4d2f949
2024 Dec 30 new playground added
Browse filesSigned-off-by: Milind Kamat <36366961+milindkamat0507@users.noreply.github.com>
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 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
st.
|
| 60 |
-
st.markdown("---")
|
| 61 |
-
|
| 62 |
-
st.subheader('Subheader')
|
| 63 |
-
st.markdown("---")
|
| 64 |
-
|
| 65 |
-
st.write('Normal text')
|
| 66 |
-
st.markdown("---")
|
| 67 |
|
| 68 |
-
|
| 69 |
-
st.
|
| 70 |
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
"Try Streamlit commands here:",
|
| 83 |
-
height=400,
|
| 84 |
-
placeholder="""Examples to try:
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
st.markdown(
|
| 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 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
-
# Tips
|
| 119 |
with st.expander("π‘ Tips & Tricks"):
|
| 120 |
st.markdown("""
|
| 121 |
-
|
| 122 |
-
-
|
| 123 |
-
-
|
| 124 |
-
-
|
| 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("---")
|