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.