Skip to content

Commit a237544

Browse files
authored
Add a section about embedding Streamlit Spaces with auto-resizing iframes
1 parent 8856e51 commit a237544

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
@@ -82,4 +82,30 @@ For example, the demo above can be embedded in these docs with the following tag
8282

8383
<iframe src="https://NimaBoscarino-hotdog-streamlit.hf.space" frameBorder="0" height="600" title="Streamlit app" class="container p-0 flex-grow space-iframe" allow="accelerometer; ambient-light-sensor; autoplay; battery; camera; document-domain; encrypted-media; fullscreen; geolocation; gyroscope; layout-animations; legacy-image-formats; magnetometer; microphone; midi; oversized-images; payment; picture-in-picture; publickey-credentials-get; sync-xhr; usb; vr ; wake-lock; xr-spatial-tracking" sandbox="allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"></iframe>
8484

85+
## Embed Streamlit Spaces with auto-resizing IFrames
86+
87+
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.
88+
89+
It relies on the [`iFrame Resizer`](https://github.com/davidjbradshaw/iframe-resizer) library, which you need to add a few lines of code to use, as in the following example where
90+
91+
- `id` is set to `<iframe />` that is used to specify the auto-resize target.
92+
- The `iFrame Resizer` is loaded via the `script` tag.
93+
- The `iFrameResize()` function is called with the ID of the target `iframe` element, so that its size changes automatically.
94+
95+
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.
96+
97+
```html
98+
<iframe
99+
id="your-iframe-id"
100+
src="https://<space-subdomain>.hf.space"
101+
frameborder="0"
102+
width="850"
103+
height="450"
104+
></iframe>
105+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/js/iframeResizer.min.js"></script>
106+
<script>
107+
iFrameResize({}, "#your-iframe-id")
108+
</script>
109+
```
110+
85111
Additionally, you can checkout [our documentation](./spaces-embed).

0 commit comments

Comments
 (0)