隐藏下方 “Made with Streamlit” 及右上角菜单栏
To hide hamburger (top right corner) and “Made with Streamlit” footer, do this :
| 1
2
3
4
5
6
7
 | hide_streamlit_style = """
            <style>
            #MainMenu {visibility: hidden;}
            footer {visibility: hidden;}
            </style>
            """
st.markdown(hide_streamlit_style, unsafe_allow_html=True) 
 | 
 
将下面内容添加到 hide_streamlit_style 里,可以改变底部显示内容
|  1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
 | footer {
	
	visibility: hidden;
	
	}
# footer {visibility: hidden;}.stApp { bottom: 10px;} # 调整footer在底部的位置
footer:after {
	content:'goodbye'; 
	visibility: visible;
	display: block;
	position: relative;
	#background-color: red;
	padding: 5px;
	top: 2px;
}
 | 
 
这个配置要放在最上面
| 1
2
3
4
5
6
 | # 只有当page_title非常长的时候,后面才不会显示 " ∙ Streamlit"
st.beta_set_page_config(
    page_title="测试++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++",
    page_icon="🦈",# “:shark:”
    layout="centered",
    initial_sidebar_state="auto",
 | 
 
| 1
2
3
4
5
6
7
 | import streamlit as st
import webbrowser
url = 'https://www.streamlit.io/'
if st.button('Open browser'):
    webbrowser.open_new_tab(url)
 | 
 
| 1
2
 | link = '[GitHub](http://github.com)'
st.markdown(link, unsafe_allow_html=True)
 | 
 
Bootstrap 改变底部
Streamlit uses Bootstrap for styling, so you have access to Bootstrap classes such as buttons and warnings. For example, here’s how to display a success badge:
| 1
2
3
4
 | st.markdown(
    '<span class="badge badge-pill badge-success"> Badge </span>',
    unsafe_allow_html=True
)
 | 
 
You can try to make a grid layout with Bootstrap, but Streamlit widgets won’t respect the layout, so it’s not a good option. ☹ ️A grid layout solution is in the works. 🙂
下载文件
|  1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
 | import os
import base64
def get_binary_file_downloader_html(bin_file, file_label='File'):
    with open(bin_file, 'rb') as f:
        data = f.read()
    bin_str = base64.b64encode(data).decode()
    href = f'<a href="data:application/octet-stream;base64,{bin_str}" download="{os.path.basename(bin_file)}">Download {file_label}</a>'
    return href
st.markdown(get_binary_file_downloader_html('photo.jpg', 'Picture'), unsafe_allow_html=True)
st.markdown(get_binary_file_downloader_html('data.csv', 'My Data'), unsafe_allow_html=True)
st.markdown(get_binary_file_downloader_html('2g1c.mp4', 'Video'), unsafe_allow_html=True)
 | 
 
如果文件是网络连接
|  1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
 | import base64
from urllib import request
def get_binary_file_downloader_html(url, file_label='File'):
    
    data = request.urlopen(url).read()
    bin_str = base64.b64encode(data).decode()
    href = f'<a href="data:application/octet-stream;base64,{bin_str}" download="{os.path.basename(url)}">Download {file_label}</a>'
    return href
st.markdown(get_binary_file_downloader_html('https://upload.wikimedia.org/wikipedia/commons/c/c4/Muriel-Nguyen-Xuan-Chopin-valse-opus64-1.ogg', 'Audio'), unsafe_allow_html=True)
 | 
 
Reference
打赏
| 微信   | 支付宝   | 
| 万分感谢 |  |