New library: streamlit-jupyter, a new way to develop streamlit apps in jupyter notebooks

Hey there, I created a library streamlit-jupyter to allow for seamless creation of streamlit apps in jupyter notebooks.

A nifty little alternative to voila, one might say.

The way this works is it detects your environment, and if the script is run from a jupyter notebook, then it wraps existing streamlit methods to replace them with ipywidgets alternatives - that way you can code as you would in streamlit, and then displays your page as-you-code.

Then you export your notebook to a .py file, and run it via streamlit as usual (no change in behaviour there)

Install

pip install streamlit_jupyter

How to use it

Take a look at our example notebook

The main idea is for you experiment and develop in your notebook,
visually see all the pieces, and then convert the notebook to .py to
be run by streamlit

start by importing streamlit and patching it with streamlit-jupyter:


import streamlit as st

from streamlit_jupyter import StreamlitPatcher, tqdm

StreamlitPatcher().jupyter()  # register streamlit with jupyter-compatible wrappers

And now develop your notebook as usual, but with the ability to use
Streamlit widgets and components.

See how it works below, and check out the example (it also incudes a nifty alternative to nbconvert that strips out all the magics and other irrelevant stuff)

Demonstration

Jupyter Streamlit
Markdown and headings
Interactive data entry
Pick and choose alt alt
Dataframes, caching and progress bars alt alt
Plots

ps

This is a very early beta and my first try at open source, so please share your thoughts and reach out with any questions/critiques!

12 Likes

This looks sweet! I can’t wait to try it out.

1 Like

Nifty! :balloon:

1 Like

Such a creative way to address the jupyter to streamlit workflow @ddzlob! I didn’t realize ipywidgets and Streamlit widgets were so “similar” before.

1 Like

Super nice!

Could you add that to the Components Tracker :slight_smile: Streamlit Components - Community Tracker so it gets synchronized with https://components.streamlit.app/ ?

Thanks again!
Fanilo

3 Likes

I didn’t realize ipywidgets and Streamlit widgets were so “similar” before

A case of convergent evolution in the engineering world! :slight_smile:

1 Like

This is super cool! Really impressive. Would love to understand a bit more about why you built this. Is it just so you can experiment more quickly with data, which is sometimes easier in a notebook environment? Or did you have any more profound use case?

1 Like

Thanks!

Yes, first use case is to try out things/charts/EDA in Jupyter and see how they look.

Second case is code and apis: I really like coding in jupyter notebook when trying to understand new concepts & APIs.

Even if I have a pure coding task at work (not related to analysing some data), I still tend to mostly work in Jupyter instead of IDEs because I feel much more productive there. And then exporting my code to a .py file.

I recently wanted to create a streamlit app at work, and found that it did not quite fit in with my preferred workflow with Jupyter - so this library was created to solve that problem :slight_smile:

4 Likes

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.