I have my app sectioned into 4 or 5 different pages (https://bea-pid-dashboard.streamlit.app/). The code here is a little ahead of the actually dashboard but I get the same issue on my local session.
option=st.sidebar.selectbox('Select Page', ('Welcome Page', 'Figures and Trends', 'Data Exploration Tool', 'State Data', 'Test',
'Fun Facts', 'Lorenz Curve'))
On the Data Exploration page the first select_box asks you want you want to do. It defaults to the create a graph function which displays well.
if option=='Data Exploration Tool':
st.title(' Data Exploration Tool')
option2=st.selectbox('What would you like to do?', ('Create a graph', 'Filter and display the raw data', 'Make a pivot table'))
if option2=='Create a graph':
# Select boxes for series and measure
option3=st.selectbox('What series would you like to graph?', data.series.unique())
if option3 in list1:
option4=st.selectbox('What measure would you like to see?', list1metrics)
elif option3 in list2:
option4=st.selectbox('What measure would you like to see?', list2metrics)
else:
option4=st.selectbox('What measure would you like to see?', list3metrics)
# Unique values that need to be assigned a percentage y axis
perc_vars=data[data.quantile_or_summary_metric.str.contains('%')].quantile_or_summary_metric.unique()
start_year, end_year=st.select_slider('Select a Date Range',
options=data.year.unique(),
value=(2000,2022))
st.write('Showing', start_year, 'through', end_year )
# Revise the below to multiple the y axis by 100 and add % sign if the measure is included in perc_vars
if option4 in perc_vars:
df=data[(data.series==option3) & (data.quantile_or_summary_metric==option4)]
df=df[df.year.between(start_year, end_year)]
df.value=pd.to_numeric(df.value)*100
df.plot.line('year', 'value', title=option3+' '+option4,
legend=False, xlabel='Year', ylabel='Percent of Total' )
else:
df=data[(data.series==option3) & (data.quantile_or_summary_metric==option4)]
df=df[df.year.between(start_year, end_year)]
df.value=pd.to_numeric(df.value)
df.plot.line('year', 'value', title=option3+' '+option4,
legend=False, xlabel='Year' )
# df=data[(data.series==option3) & (data.quantile_or_summary_metric==option4)]
# df=df[df.year.between(start_year, end_year)].copy()
# df.value=pd.to_numeric(df.value)
# df.plot.line('year', 'value', title=option3+' '+option4,
# legend=False, xlabel='Year' )
st.pyplot(plt.gcf())
However, if you select any of the other values nothing shows up. For example,
if option2=='Filter and display raw data':
# Test Line
st.write('This tool allows you to filter the data by series and measure')
option5=st.selectbox('What series would you like to graph?', data.series.unique())
option6=st.selectbox('What measure would you like to see?', data.quantile_or_summary_metric.unique())
# # Display the data filter by the series and measure
# st.dataframe(data[(data.series==option5) & (data.quantile_or_summary_metric==option6)])
There is an indent for the first line above btw.
I’m not sure why there is not output. I have named the new select_boxes unique names. The st.write doesn’t even show up. Any ideas?