-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils_streamlit.py
64 lines (55 loc) · 1.72 KB
/
utils_streamlit.py
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
"""
Utils for streamlit
"""
import streamlit as st
import streamlit.components.v1 as components
# https://discuss.streamlit.io/t/prevent-st-text-input-from-triggering-callback-when-losing-focus/37103/3
def streamlit_hack_disable_textarea_submit():
"""Do not submit TextArea component when lost focus"""
components.html(
"""
<script>
const doc = window.parent.document;
const textareas = doc.querySelectorAll('textarea');
textareas.forEach(textarea => {
textarea.addEventListener('focusout', function(event) {
event.stopPropagation();
event.preventDefault();
});
});
const inputs = doc.querySelectorAll('input');
inputs.forEach(input => {
input.addEventListener('focusout', function(event) {
event.stopPropagation();
event.preventDefault();
});
});
</script>""",
height=0,
width=0,
)
def streamlit_hack_remove_top_space():
"""Remove top space of streamlit windos"""
st.markdown("""
<style>
.block-container {
padding-top: 1rem;
}
</style>
""", unsafe_allow_html=True)
st.markdown("""
<style>
.css-1544g2n {
padding-top: 2rem;
}
</style>
""", unsafe_allow_html=True)
def hide_footer():
"""Hide footer"""
hide_streamlit_style = """
<style>
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
</style>
"""
st.markdown(hide_streamlit_style, unsafe_allow_html=True)