Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,159 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import plotly.figure_factory as ff
|
3 |
+
import numpy as np
|
4 |
+
import random
|
5 |
+
|
6 |
+
|
7 |
+
# This code is different for each deployed app.
|
8 |
+
CURRENT_THEME = "blue"
|
9 |
+
IS_DARK_THEME = True
|
10 |
+
EXPANDER_TEXT = """
|
11 |
+
This is a custom theme. You can enable it by copying the following code
|
12 |
+
to `.streamlit/config.toml`:
|
13 |
+
```python
|
14 |
+
[theme]
|
15 |
+
primaryColor = "#E694FF"
|
16 |
+
backgroundColor = "#00172B"
|
17 |
+
secondaryBackgroundColor = "#0083B8"
|
18 |
+
textColor = "#C6CDD4"
|
19 |
+
font = "sans-serif"
|
20 |
+
```
|
21 |
+
"""
|
22 |
+
|
23 |
+
|
24 |
+
# This code is the same for each deployed app.
|
25 |
+
st.image(
|
26 |
+
"https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/240/apple/271/artist-palette_1f3a8.png",
|
27 |
+
width=100,
|
28 |
+
)
|
29 |
+
|
30 |
+
"""
|
31 |
+
# Try out Theming!
|
32 |
+
Click on the images below to view this app with different themes.
|
33 |
+
"""
|
34 |
+
|
35 |
+
""
|
36 |
+
|
37 |
+
THEMES = [
|
38 |
+
"light",
|
39 |
+
"dark",
|
40 |
+
"green",
|
41 |
+
"blue",
|
42 |
+
]
|
43 |
+
GITHUB_OWNER = "streamlit"
|
44 |
+
|
45 |
+
# Show thumbnails for available themes.
|
46 |
+
# As html img tags here, so we can add links on them.
|
47 |
+
cols = st.columns(len(THEMES))
|
48 |
+
for col, theme in zip(cols, THEMES):
|
49 |
+
|
50 |
+
# Get repo name for this theme (to link to correct deployed app)-
|
51 |
+
if theme == "light":
|
52 |
+
repo = "theming-showcase"
|
53 |
+
else:
|
54 |
+
repo = f"theming-showcase-{theme}"
|
55 |
+
|
56 |
+
# Set border of current theme to red, otherwise black or white
|
57 |
+
if theme == CURRENT_THEME:
|
58 |
+
border_color = "red"
|
59 |
+
else:
|
60 |
+
border_color = "lightgrey" if IS_DARK_THEME else "black"
|
61 |
+
|
62 |
+
col.markdown(
|
63 |
+
#f'<p align=center><a href="https://share.streamlit.io/{GITHUB_OWNER}/{repo}/main"><img style="border: 1px solid {border_color}" alt="{theme}" src="https://raw.githubusercontent.com/{GITHUB_OWNER}/theming-showcase/main/thumbnails/{theme}.png" width=150></a></p>',
|
64 |
+
f'<p align=center><a href="https://apps.streamlitusercontent.com/{GITHUB_OWNER}/{repo}/main/streamlit_app.py/+/"><img style="border: 1px solid {border_color}" alt="{theme}" src="https://raw.githubusercontent.com/{GITHUB_OWNER}/theming-showcase/main/thumbnails/{theme}.png" width=150></a></p>',
|
65 |
+
unsafe_allow_html=True,
|
66 |
+
)
|
67 |
+
if theme in ["light", "dark"]:
|
68 |
+
theme_descriptor = theme.capitalize() + " theme"
|
69 |
+
else:
|
70 |
+
theme_descriptor = "Custom theme"
|
71 |
+
col.write(f"<p align=center>{theme_descriptor}</p>", unsafe_allow_html=True)
|
72 |
+
|
73 |
+
|
74 |
+
""
|
75 |
+
with st.expander("Not loading?"):
|
76 |
+
st.write(
|
77 |
+
"You probably played around with themes before and overrode this app's theme. Go to β° -> Settings -> Theme and select *Custom Theme*."
|
78 |
+
)
|
79 |
+
with st.expander("How can I use this theme in my app?"):
|
80 |
+
st.write(EXPANDER_TEXT)
|
81 |
+
|
82 |
+
""
|
83 |
+
""
|
84 |
+
|
85 |
+
# Draw some dummy content in main page and sidebar.
|
86 |
+
def draw_all(
|
87 |
+
key,
|
88 |
+
plot=False,
|
89 |
+
):
|
90 |
+
st.write(
|
91 |
+
"""
|
92 |
+
# Example Widgets
|
93 |
+
|
94 |
+
These widgets don't do anything. But look at all the new colors they got π
|
95 |
+
|
96 |
+
```python
|
97 |
+
# First some code.
|
98 |
+
streamlit = "cool"
|
99 |
+
theming = "fantastic"
|
100 |
+
both = "π₯"
|
101 |
+
```
|
102 |
+
"""
|
103 |
+
)
|
104 |
+
|
105 |
+
st.checkbox("Is this cool or what?", key=str(random.randint(0, 10000)))
|
106 |
+
st.radio(
|
107 |
+
"How many balloons?",
|
108 |
+
["1 balloon π", "2 balloons ππ", "3 balloons πππ"],
|
109 |
+
key=str(random.randint(0, 10000)),
|
110 |
+
)
|
111 |
+
st.button("π€‘ Click me", key=str(random.randint(0, 10000)))
|
112 |
+
|
113 |
+
# if plot:
|
114 |
+
# st.write("Oh look, a plot:")
|
115 |
+
# x1 = np.random.randn(200) - 2
|
116 |
+
# x2 = np.random.randn(200)
|
117 |
+
# x3 = np.random.randn(200) + 2
|
118 |
+
|
119 |
+
# hist_data = [x1, x2, x3]
|
120 |
+
# group_labels = ["Group 1", "Group 2", "Group 3"]
|
121 |
+
|
122 |
+
# fig = ff.create_distplot(hist_data, group_labels, bin_size=[0.1, 0.25, 0.5])
|
123 |
+
|
124 |
+
# st.plotly_chart(fig, use_container_width=True)
|
125 |
+
|
126 |
+
st.file_uploader("You can now upload with style", key=str(random.randint(0, 10000)))
|
127 |
+
st.slider(
|
128 |
+
"From 10 to 11, how cool are themes?", min_value=10, max_value=11, key=str(random.randint(0, 10000))
|
129 |
+
)
|
130 |
+
# st.select_slider("Pick a number", [1, 2, 3], key=key)
|
131 |
+
st.number_input("So many numbers", key=str(random.randint(0, 10000)))
|
132 |
+
st.text_area("A little writing space for you :)", key=str(random.randint(0, 10000)))
|
133 |
+
st.text_input("Text input :)", key=str(random.randint(0, 10000)))
|
134 |
+
st.selectbox(
|
135 |
+
"My favorite thing in the world is...",
|
136 |
+
["Streamlit", "Theming", "Baloooons π "],
|
137 |
+
key=str(random.randint(0, 10000)),
|
138 |
+
)
|
139 |
+
# st.multiselect("Pick a number", [1, 2, 3], key=key)
|
140 |
+
# st.color_picker("Colors, colors, colors", key=key)
|
141 |
+
with st.expander("Expand me!"):
|
142 |
+
st.write("Hey there! Nothing to see here π ")
|
143 |
+
st.write("")
|
144 |
+
# st.write("That's our progress on theming:")
|
145 |
+
# st.progress(0.99)
|
146 |
+
if plot:
|
147 |
+
st.write("And here's some data and plots")
|
148 |
+
st.json({"data": [1, 2, 3, 4]})
|
149 |
+
st.dataframe({"data": [1, 2, 3, 4]})
|
150 |
+
st.table({"data": [1, 2, 3, 4]})
|
151 |
+
st.line_chart({"data": [1, 2, 3, 4]})
|
152 |
+
# st.help(st.write)
|
153 |
+
st.write("This is the end. Have fun building themes!")
|
154 |
+
|
155 |
+
|
156 |
+
draw_all("main", plot=True)
|
157 |
+
|
158 |
+
with st.sidebar:
|
159 |
+
draw_all("sidebar")
|