chore(streamlit): migrate components.v1.html → st.iframe (deprecation)

Streamlit logs a deprecation notice on every render:

  Please replace ``st.components.v1.html`` with ``st.iframe``.
  ``st.components.v1.html`` will be removed after 2026-06-01.

Replace all 9 call sites (6 tool pages + 3 in ``_legacy.py``).
Both APIs feed ``srcdoc`` to the underlying iframe so the
HTML/JS payload and the cross-frame DOM access pattern
(``window.parent.document``) are unchanged.

``st.iframe`` rejects ``height=0`` (raises ``StreamlitInvalid
HeightError``), so bump every zero-height call to ``height=1``.
1px is effectively invisible — these are script-only iframes, no
visible payload — and avoids the validator.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-18 15:57:40 +00:00
parent 4a7f99f0ec
commit b568773a1f
7 changed files with 18 additions and 27 deletions

View File

@@ -781,8 +781,7 @@ a[data-testid="stPageLink"][href$="/close/"] {
except Exception:
pass
from streamlit.components.v1 import html as _components_html
_components_html(
st.iframe(
f"""
<script>
(function () {{
@@ -861,7 +860,7 @@ a[data-testid="stPageLink"][href$="/close/"] {
}})();
</script>
""",
height=0,
height=1,
)
@@ -881,7 +880,7 @@ def _render_sticky_footer_DISABLED() -> None:
1. ``st.markdown`` injects the CSS rules into the parent document.
Class-targeted, so the rules apply once the footer DOM node
exists regardless of where it lives.
2. ``streamlit.components.v1.html`` renders a zero-height iframe
2. ``st.iframe`` renders a zero-height iframe
whose JS reaches ``window.parent.document`` and creates / moves
a ``#datatools-sticky-footer`` div directly under ``<body>``.
This bypasses every Streamlit container.
@@ -951,8 +950,7 @@ def _render_sticky_footer_DISABLED() -> None:
# reachable; if a sandbox config ever blocks that we fall back to
# rendering inside the iframe itself (still visible, just sized
# to the iframe rather than the viewport).
from streamlit.components.v1 import html as _components_html
_components_html(
st.iframe(
f"""
<script>
(function () {{
@@ -987,7 +985,7 @@ def _render_sticky_footer_DISABLED() -> None:
}})();
</script>
""",
height=0,
height=1,
)
@@ -1058,8 +1056,7 @@ def shutdown_app() -> None:
threading.Thread(target=_hard_exit, daemon=True).start()
from streamlit.components.v1 import html as _components_html
_components_html(_farewell_script(), height=0)
st.iframe(_farewell_script(), height=1)
st.success(_t("quit.shutting_down"))
st.stop()