Spaces:
Running
Running
rmm
commited on
Commit
·
f3eb9f5
1
Parent(s):
96df9de
docs: docstrings, typehints for js iframe /tab fix code
Browse files- call_models/fix_tabrender.py +37 -1
- docs/fix_tabrender.md +0 -1
call_models/fix_tabrender.py
CHANGED
@@ -10,6 +10,21 @@ import streamlit as st
|
|
10 |
import uuid, html
|
11 |
# workaround for streamlit making tabs height 0 when not active, breaks map
|
12 |
def inject_iframe_js_code(source: str) -> None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
div_id = uuid.uuid4()
|
14 |
|
15 |
st.markdown(
|
@@ -28,7 +43,28 @@ def inject_iframe_js_code(source: str) -> None:
|
|
28 |
unsafe_allow_html=True,
|
29 |
)
|
30 |
|
31 |
-
def js_show_zeroheight_iframe(component_iframe_title: str, height: str = "auto"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
source = f"""
|
33 |
(function() {{
|
34 |
var attempts = 0;
|
|
|
10 |
import uuid, html
|
11 |
# workaround for streamlit making tabs height 0 when not active, breaks map
|
12 |
def inject_iframe_js_code(source: str) -> None:
|
13 |
+
"""
|
14 |
+
Injects JavaScript code into a Streamlit app using an iframe.
|
15 |
+
|
16 |
+
This function creates a hidden div with a unique ID and injects the provided
|
17 |
+
JavaScript code into the parent document using an iframe. The iframe's source
|
18 |
+
is a JavaScript URL that creates a script element, sets its type to 'text/javascript',
|
19 |
+
and assigns the provided JavaScript code to its text content. The script element
|
20 |
+
is then appended to the hidden div in the parent document.
|
21 |
+
|
22 |
+
Args:
|
23 |
+
source (str): The JavaScript code to be injected.
|
24 |
+
|
25 |
+
Returns:
|
26 |
+
None
|
27 |
+
"""
|
28 |
div_id = uuid.uuid4()
|
29 |
|
30 |
st.markdown(
|
|
|
43 |
unsafe_allow_html=True,
|
44 |
)
|
45 |
|
46 |
+
def js_show_zeroheight_iframe(component_iframe_title: str, height: str = "auto") -> None:
|
47 |
+
"""
|
48 |
+
Injects JavaScript code to dynamically set iframe height (located by title)
|
49 |
+
|
50 |
+
This function generates and injects JavaScript code that searches for
|
51 |
+
iframes with the given title and sets their height to the specified value.
|
52 |
+
The script attempts to find the iframes up to a maximum number of attempts,
|
53 |
+
and also listens for user interactions to reattempt setting the height.
|
54 |
+
|
55 |
+
See https://github.com/streamlit/streamlit/issues/7376
|
56 |
+
|
57 |
+
|
58 |
+
Args:
|
59 |
+
component_iframe_title (str): The title attribute of the iframes to target.
|
60 |
+
height (str, optional): The height to set for the iframes. Defaults to "auto".
|
61 |
+
|
62 |
+
Notes:
|
63 |
+
- The JavaScript code will attempt to find the iframes every 250
|
64 |
+
milliseconds, up to a maximum of 20 attempts.
|
65 |
+
- If the iframes are found, their height will be set to the specified value.
|
66 |
+
- User interactions (e.g., click events) triggers a reattempt to set the height.
|
67 |
+
"""
|
68 |
source = f"""
|
69 |
(function() {{
|
70 |
var attempts = 0;
|
docs/fix_tabrender.md
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
|
2 |
A js fix for certain UI elements, including maps, getting rendered into a
|
3 |
zero-sized frame by default. Here we resize it so it is visible once the tab is
|
4 |
clicked and no further interaction is required to see it.
|
|
|
|
|
1 |
A js fix for certain UI elements, including maps, getting rendered into a
|
2 |
zero-sized frame by default. Here we resize it so it is visible once the tab is
|
3 |
clicked and no further interaction is required to see it.
|