Running Jupyter cells inside streamlit?

A few use cases we have in mind for Streamlit encourage writing of code:

  1. Write a regex, visualize selection of gradients/activations that correspond to the rules
  2. Customize viz code inline to change the way data is presented

Is there any way to embed or execute a Jupyter cell inside of a streamlit app? Obviously I could use an iframe, but love to have a cell that exists within the broader context of the app.

Hi @kossnick

There’s no way to embed a Jupyter cell in Streamlit but you could emulate that using text areas:

import streamlit as st
import numpy as np
import matplotlib.pyplot as plt


'''
Try changing the code in the text area below to
`plt.plot(data[:, 1])`
'''

data = np.random.randn(100, 2)
default_code = 'plt.plot(data)'
code = st.text_area('Enter some code', default_code)

exec(code, locals())
st.pyplot()

Of course, you should only let trusted users use this script! You’re allowing people to run arbitrary Python code, which means they can cause a lot of damage on your machine.

Is this still the case? @thiago way to wrap Jupyter cell into streamlit would go along way.

Lots of options now for creating dashboards from Jupyter via dash , voila.

But streamlight would be the perfect scaffold.

Yup, it’s still the case.

What did you have in mind, by the way?

If you want to do live Jupyter-style exploratory analysis, I find that with my text editor on the left side of the screen and my browser on the right, I can use Streamlit’s automatic rerun feature to update the browser every time I press ctrl-s on my editor (to save the script). This gives me a super fast iterative loop, that feels great.

You may need to sprinkle some st.cache here and there as the need arises, but the nice thing is that at the end of your fun exploratory coding session you end up with a really nice Streamlit app.


Alternatively, if what you’re looking for is some way to allow your viewers to edit some part of your code, some time ago I wrapped the snippet above into a slightly more usable form and published as a Streamlit component called execbox, which may be useful for that.