Running streamlit in a Jupyter cell?

The Streamlit UI library is very easy to use as a dev and a user. Is there any way to generate the UI inside a single Jupyter cell? I understand the use case of “graduating” a notebook into an internal app and only using streamlit. However, for the case where we’re still iterating on code frequently, it would still be nice to use the UI library in a notebook.

Hi @kossnick

It’s not currently possible to run Streamlit inside Jupyter. There are several reasons for this, but the most fundamental one is: Streamlit starts a server on the main thread, so it would block the Jupyter kernel and you wouldn’t be able to use it for anything else.

However, for the case where we’re still iterating on code frequently, it would still be nice to use the UI library in a notebook.

The way Streamlit addresses the problem of “quick iteration”, is to watch your Python files and live-update the app when the files change.

So the quick iteration loop in Streamlit is:

  1. write my_app.py
  2. strealmit run my_app.py
  3. edit my_app.py and save
  4. click “Always rerun” on the top-right prompt in Streamlit
    From now on every time you save the app will immediately update.
    So:
  5. edit my_app.py and save again
    → The app will automatically update
  6. edit my_app.py and save again
    → The app will automatically update
    etc.
1 Like