-
Notifications
You must be signed in to change notification settings - Fork 0
/
streamlit_utils.py
49 lines (41 loc) · 1.32 KB
/
streamlit_utils.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
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():
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():
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)