# Streamlit

{% embed url="<https://www.youtube.com/watch?v=bYQPjvKVnUw>" %}

Streamlit is [a platform for building and sharing data apps written in Python](https://streamlit.io/). With PixieBrix, you can embed a Streamlit data app on any web page or application. Additionally, you can pass context to the page to the Streamlit app.

<figure><img src="https://2274778196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq123bF1HPQPV35s5vHa1%2Fuploads%2Frum0cG5YcleNnbENxw7Y%2Fimage.png?alt=media&#x26;token=7226f6bd-13ca-49f1-9037-880ee67d5ae2" alt=""><figcaption><p>30 Days of Streamlit app in the PixieBrix sidebar</p></figcaption></figure>

### Embedding a Streamlit App

{% hint style="warning" %}
The Streamlit Community Cloud does not support embedding private Streamlit apps
{% endhint %}

PixieBrix supports embedding a [Streamlit app via an iframe](https://docs.streamlit.io/streamlit-community-cloud/share-your-app/embed-your-app#embedding-with-iframes). To embed a Streamlit app:

1. Create a new Mod Component with the "Sidebar Panel" starter brick
2. Remove the Render Document Brick
3. Add the IFrame brick
4. Provide the URL for the public app with `?embed=true` appended to the URL. (Providing the embed parameter removes excess UI and padding from the app)

<figure><img src="https://2274778196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq123bF1HPQPV35s5vHa1%2Fuploads%2FSQfSrHQFiAtgGc4HTc3j%2Fimage.png?alt=media&#x26;token=f205edef-3dbc-46a1-8654-6b396eb119e0" alt=""><figcaption><p>Configuring a Sidebar mod to display a public Streamlit app</p></figcaption></figure>

#### Embed Options

Public Streamlit apps embedded via an iframe support the following [embed options to customize the UI of the embed](https://docs.streamlit.io/streamlit-community-cloud/share-your-app/embed-your-app#embed-options). To provide an embed option, provide one or more `embed_options` query parameters with the iframe URL:&#x20;

* show\_toolbar
* show\_padding
* show\_footer
* show\_colored\_line
* hide\_loading\_screen
* disable\_scrolling
* light\_theme
* dark\_theme

You can use the Streamlit [app's menu to create an embed link](https://docs.streamlit.io/streamlit-community-cloud/share-your-app/embed-your-app#build-an-embed-link).

### Passing Page Context to a Streamlit App

Page Context is passed to Streamlit via URL query parameters. To accept URL query parameters in your Streamlit app, use Streamlit's [st.query\_params utility](https://docs.streamlit.io/library/api-reference/utilities/st.query_params).

For example:

```python
inputs = st.query_params.to_dict()
st.title(f'URL param demo: {inputs.get("first_key")}')
```

In PixieBrix, use the Construct URL brick to construct a URL given the parameters. Provide the constructed URL to the IFrame brick:

<figure><img src="https://2274778196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fq123bF1HPQPV35s5vHa1%2Fuploads%2F0yl7mHlzKfRhgJvuje8b%2Fimage.png?alt=media&#x26;token=40bfb833-17d1-4d61-bf85-34f1cf6693a2" alt=""><figcaption><p>Constructing a Streamlit app URL in PixieBrix</p></figcaption></figure>
