Fix crash when navigating to a folder with no JSON files
st.radio was called with an empty list when no JSON files existed, causing Streamlit to error and only render the sidebar. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
13
app.py
13
app.py
@@ -147,12 +147,17 @@ with st.sidebar:
|
|||||||
st.rerun()
|
st.rerun()
|
||||||
|
|
||||||
# --- File Selector ---
|
# --- File Selector ---
|
||||||
|
selected_file_name = None
|
||||||
|
if json_files:
|
||||||
|
file_names = [f.name for f in json_files]
|
||||||
if 'file_selector' not in st.session_state:
|
if 'file_selector' not in st.session_state:
|
||||||
st.session_state.file_selector = json_files[0].name if json_files else None
|
st.session_state.file_selector = file_names[0]
|
||||||
if st.session_state.file_selector not in [f.name for f in json_files] and json_files:
|
if st.session_state.file_selector not in file_names:
|
||||||
st.session_state.file_selector = json_files[0].name
|
st.session_state.file_selector = file_names[0]
|
||||||
|
|
||||||
selected_file_name = st.radio("Select File", [f.name for f in json_files], key="file_selector")
|
selected_file_name = st.radio("Select File", file_names, key="file_selector")
|
||||||
|
else:
|
||||||
|
st.info("No JSON files in this folder.")
|
||||||
|
|
||||||
# --- GLOBAL MONITOR TOGGLE (NEW) ---
|
# --- GLOBAL MONITOR TOGGLE (NEW) ---
|
||||||
st.markdown("---")
|
st.markdown("---")
|
||||||
|
|||||||
Reference in New Issue
Block a user