cbensimon HF staff commited on
Commit
a485e3e
1 Parent(s): c404762

Create app.py

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