Skip to content

Commit 8997a37

Browse files
Add a section about embedding Streamlit Spaces with auto-resizing iframes (#691)
* Add a section about embedding Streamlit Spaces with auto-resizing iframes * Update docs/hub/spaces-sdks-streamlit.md Co-authored-by: christophe-rannou <christophe@huggingface.co> --------- Co-authored-by: christophe-rannou <christophe@huggingface.co>
1 parent 2ee902e commit 8997a37

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/hub/spaces-sdks-streamlit.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,30 @@ For example, the demo above can be embedded in these docs with the following tag
9797
Please note that we have added `?embed=true` to the URL, which activates the embed mode of the Streamlit app, removing some spacers and the footer for slim embeds.
9898

9999

100+
## Embed Streamlit Spaces with auto-resizing IFrames
101+
102+
Streamlit has supported automatic iframe resizing since [1.17.0](https://docs.streamlit.io/library/changelog#version-1170) so that the size of the parent iframe is automatically adjusted to fit the content volume of the embedded Streamlit application.
103+
104+
It relies on the [`iFrame Resizer`](https://github.com/davidjbradshaw/iframe-resizer) library, for which you need to add a few lines of code, as in the following example where
105+
106+
- `id` is set to `<iframe />` that is used to specify the auto-resize target.
107+
- The `iFrame Resizer` is loaded via the `script` tag.
108+
- The `iFrameResize()` function is called with the ID of the target `iframe` element, so that its size changes automatically.
109+
110+
We can pass options to the first argument of `iFrameResize()`. See [the document](https://github.com/davidjbradshaw/iframe-resizer/blob/master/docs/parent_page/options.md) for the details.
111+
112+
```html
113+
<iframe
114+
id="your-iframe-id"
115+
src="https://<space-subdomain>.hf.space"
116+
frameborder="0"
117+
width="850"
118+
height="450"
119+
></iframe>
120+
<script src="https://cdn.jsdelivr.net/npm/iframe-resizer@4.3.4/js/iframeResizer.min.js"></script>
121+
<script>
122+
iFrameResize({}, "#your-iframe-id")
123+
</script>
124+
```
125+
100126
Additionally, you can checkout [our documentation](./spaces-embed).

0 commit comments

Comments
 (0)