Skip to main content

44  Embedding apps in Quarto


If you write documentation, reports or teaching materials in Quarto, you can embed a Streamlit app directly in the page. This lets people try the app without leaving the document.

There are two main approaches:


44.1 Using iframes

An iframe displays another web page inside your page. If your app is already deployed, this is the quickest way to embed it.


44.1.1 Streamlit Community Cloud

Wrap this in a raw HTML block ({=html}) so Quarto renders the iframe instead of showing it as code.

Add ?embed=true to the end of a Community Cloud URL to hide some of Streamlit’s surrounding interface (such as the menu), so the app fits more cleanly into your page.

<iframe width="100%" height="600" src="https://hsma-des-simple.streamlit.app/?embed=true" title="DES app"></iframe>


44.1.2 stlite

This is an stlite app hosted on GitHub pages. We can embed it in the same way.

<iframe width="100%" height="600" src="https://hsma-programme.github.io/hsma7_2g_streamlit_part1/app/singlepage/" title="DES app"></iframe>


44.2 Directly using stlite

You can also run an stlite app inside the Quarto page, with no separate hosting. This uses the quarto-stlite extension from Yuichiro Tachibana, who created stlite.

  1. Install the extension by running the following command in your terminal. This will install the extension in an _extensions folder.
quarto add whitphx/quarto-stlite
  1. Add the filter to the header of your .qmd file, or to _quarto.yml to use it across the whole project.
filters:
  - whitphx/stlite
  1. Put your app code in a code block marked {stlite-python}.
```{stlite-python}
import streamlit as st

st.title("Hello Quarto!")
```
import streamlit as st

st.title("Hello Quarto!")


44.2.1 Limitation 1: Installing packages

Some packages, such as streamlit and pandas, are available by default. For others, install them in the page with micropip before importing them. For example:

import micropip
await micropip.install("folium")

import folium

Some imports need to be written differently when using this extension. Plotly and matplotlib don’t work with the import ... as ... shorthand you’d normally use:

  • Use from plotly import express as px, not import plotly.express as px.
  • Use from matplotlib import pyplot as plt, not import matplotlib.pyplot as plt.

For example, for matplotlib:

import micropip
await micropip.install("matplotlib")

from matplotlib import pyplot as plt


44.2.2 Limitation 2: Multi-page apps and configuration

You can’t create multi-page apps with {stlite-python} blocks.

You also can’t use a config.toml file, so settings such as the theme can’t be changed this way.

If you need either of these, host the app separately and embed it with an iframe instead.

Back to top