-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathlogos.qmd
More file actions
189 lines (137 loc) · 4.82 KB
/
logos.qmd
File metadata and controls
189 lines (137 loc) · 4.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
---
title: "Logos"
filters:
- whitphx/stlite
---
Streamlit has basic support for small logos in your app.
It will look for a file you specify relative to the currently running streamlit file
here, for example, it looks for a folder called ‘resources’ and then looks for the ‘hsma_logo.png’ file.

The logo will appear in the top left of your app.
:::{.callout-tip}
The command to insert a logo is
`st.logo("your_filepath_here")`
e.g. `st.logo("resources/hsma_logo.png")`
:::
```{python}
#| eval: false
import streamlit as st
st.logo("resources/hsma_logo.png")
st.title('Simple Calculator App')
num_1 = st.number_input(label="First Number")
num_2 = st.number_input(label="Second Number")
operator = st.selectbox(label="Operation", options=["Add", "Subtract", "Multiply", "Divide"])
if operator == "Add":
output = num_1 + num_2
elif operator == "Subtract":
output = num_1 - num_2
elif operator == "Multiply":
output = num_1 * num_2
elif operator == "Divide":
output = num_1 / num_2
st.text(f"The answer is {output}")
```
If it’s a multi page app or an app using a streamlit sidebar that you have manually defined, it will appear at the top of the sidebar.
```{python}
#| eval: false
import streamlit as st
st.logo("resources/hsma_logo.png")
st.title('Simple Calculator App')
with st.sidebar:
num_1 = st.number_input(label="First Number")
num_2 = st.number_input(label="Second Number")
operator = st.selectbox(label="Operation", options=["Add", "Subtract", "Multiply", "Divide"])
if operator == "Add":
output = num_1 + num_2
elif operator == "Subtract":
output = num_1 - num_2
elif operator == "Multiply":
output = num_1 * num_2
elif operator == "Divide":
output = num_1 / num_2
st.text(f"The answer is {output}")
```
:::{.callout-tip}
Ideally, your logo should be close to 24 pixels tall by 240 pixels wide.
:::
## Larger logos
It is possible to include larger logos through more advanced tricks, but they are fragile and prone to breaking as changes are made to the Streamlit library.

The approach requires using some markdown to inject some custom CSS (see the fonts chapter for more details on CSS).
Here is a reusable function you could adapt to your own use:
```{python}
#| eval: false
def add_logo():
'''
Add a logo at the top of the page navigation sidebar
Approach written by blackary on
https://discuss.streamlit.io/t/put-logo-and-title-above-on-top-of-page-navigation-in-sidebar-of-multipage-app/28213/5
'''
st.markdown(
"""
<style>
[data-testid="stSidebarNav"] {
background-image: url(https://raw.githubusercontent.com/hsma-programme/Teaching_DES_Concepts_Streamlit/main/resources/hsma_logo_transparent_background_small.png);
background-repeat: no-repeat;
padding-top: 175px;
background-position: 40px 30px;
}
[data-testid="stSidebarNav"]::before {
content: "The DES Playground";
padding-left: 20px;
margin-top: 50px;
font-size: 30px;
position: relative;
top: 100px;
}
</style>
""",
unsafe_allow_html=True,
)
```
```{python}
#| eval: false
import streamlit as st
def add_logo():
'''
Add a logo at the top of the page navigation sidebar
Approach written by blackary on
https://discuss.streamlit.io/t/put-logo-and-title-above-on-top-of-page-navigation-in-sidebar-of-multipage-app/28213/5
'''
st.markdown(
"""
<style>
[data-testid="stSidebarNav"] {
background-image: url(https://raw.githubusercontent.com/hsma-programme/Teaching_DES_Concepts_Streamlit/main/resources/hsma_logo_transparent_background_small.png);
background-repeat: no-repeat;
padding-top: 175px;
background-position: 40px 30px;
}
[data-testid="stSidebarNav"]::before {
content: "The DES Playground";
padding-left: 20px;
margin-top: 50px;
font-size: 30px;
position: relative;
top: 100px;
}
</style>
""",
unsafe_allow_html=True,
)
add_logo()
st.title('Simple Calculator App')
with st.sidebar:
num_1 = st.number_input(label="First Number")
num_2 = st.number_input(label="Second Number")
operator = st.selectbox(label="Operation", options=["Add", "Subtract", "Multiply", "Divide"])
if operator == "Add":
output = num_1 + num_2
elif operator == "Subtract":
output = num_1 - num_2
elif operator == "Multiply":
output = num_1 * num_2
elif operator == "Divide":
output = num_1 / num_2
st.text(f"The answer is {output}")
```