Skip to content

Instantly share code, notes, and snippets.

@asehmi
Created December 14, 2021 15:39
Show Gist options
  • Save asehmi/c8f5fb302bd39660d2f67241b92020d8 to your computer and use it in GitHub Desktop.
Save asehmi/c8f5fb302bd39660d2f67241b92020d8 to your computer and use it in GitHub Desktop.
Showing/hiding Streamlit panel containers
import streamlit as st
import numpy as np
c1, c2 = st.columns([1,1])
show_p1 = c1.checkbox('Show panel 1', True)
show_p2 = c2.checkbox('Show panel 2', True)
panel1 = c1.empty()
panel2 = c2.empty()
@st.experimental_memo()
def data(X, Y):
return np.random.randn(X, Y)
if show_p1:
with panel1.container():
st.bar_chart(data(10,3))
else:
c1.write('Empty!')
panel1 = st.empty()
if show_p2:
with panel2.container():
st.bar_chart(data(5,6))
else:
c2.write('Empty!')
panel2 = st.empty()
@asehmi
Copy link
Author

asehmi commented Apr 19, 2022

clear_container

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment