am trying to use columns in my streamlit layout where the app includes 2 checkboxes and the streamlit app plot the graphs in these 2 columns.
problem is :
if the user select 1 checkbox the same graph its displayed in first column and the second column.
If user select 2 checkbox the graphs are displayed in first and second columns.
My question is how to display the graphs in the right way?
meaning if the user check 1 checkbox it display just in one column
Note i am using st.beta_column + with
code:
import streamlit as st.
col1,col2 = st.beta_columns(2)
form = st.sidebar.form("checkboxes")
with form:
pie_chart_box = st.checkbox("Pie Plot")
count_plot_box = st.checkbox("Count_plot")
groupBy_box = st.checkbox("GroupBy")
plot_btn = st.form_submit_button("Generate Plot")
#plotting choosen options
if plot_btn:
with col1:
if pie_chart_box:
col1.title("Plotting Single filed")
data_pie = df[col].value_counts().to_frame()
labels=data_pie.index.tolist()
datavals=data_pie[col].tolist()
trace=go.Pie(labels=labels,
values=datavals,
hovertemplate = "%{label}: <br>Value: %{value} ",
showlegend=True,
textposition='inside',
)
layout = go.Layout(
title = 'Percentage of {}'.format(col),
height=600,
)
data = [trace]
fig = go.Figure(data=data,layout = layout)
elif count_plot_box:
col1.title("Plotting Single filed")
s=df[col].str.strip().value_counts()
trace = go.Bar(
x=s.index,
y=s.values,
showlegend = True
)
layout = go.Layout(
title = 'Count of {}'.format(col),
)
data = [trace]
fig = go.Figure(data=data,layout = layout)
elif groupBy_box == True and pie_chart_box == False and count_plot_box == False:
col1.title("Plotting Multiple fileds")
if type_of_plot=="bar":
fig = px.bar(df,x=col,y="Rating",color = selected_column_names__pyplot[0],barmode ="group")
st.plotly_chart(fig, use_container_width=True)
with col2:
if groupBy_box :
col2.title("Plotting Multiple fileds")
if type_of_plot=="bar":
fig = px.bar(df,x=col,y="Rating",color = selected_column_names__pyplot[0],barmode ="group")
elif count_plot_box:
if df[col].dtype == np.float64 or df[col].dtype == np.int64 or df[col].dtype == np.float32 or df[col].dtype == np.int32:
st.markdown('<font color=red>Error: Your are Plotting Count For Numerical Values!! </font>', unsafe_allow_html=True)
else:
col2.title("Count Plot")
s=df[col].str.strip().value_counts()
trace = go.Bar(
x=s.index,
y=s.values,
showlegend = True
)
layout = go.Layout(
title = 'Count of {}'.format(col),
)
data = [trace]
fig = go.Figure(data=data,layout = layout)
st.plotly_chart(fig, use_container_width=True)