Hello,
I am experiencing an issue with my Streamlit application where I am unable to view the contents of an uploaded JSON file. Upon uploading the file, the application does not display the JSON data as expected. Here is the code snippet used for the upload and display functionality:
import streamlit as st
import json
if st.button("Enter your Json Data"):
with st.container():
option = st.radio("Do you want to upload a JSON file?", ("Yes", "No"))
if option == "Yes":
uploaded_file = st.file_uploader("Choose a JSON file", type="json")
if uploaded_file is not None:
# Read the file and convert to JSON
input_data = json.load(uploaded_file)
# Use st.session_state to cache the data
st.session_state['json_data'] = input_data
st.json(input_data)
else:
st.warning("Please upload a JSON file.")
else:
if 'json_data' in st.session_state:
# Display the cached JSON data
st.json(st.session_state['json_data'])
else:
st.warning("No JSON data uploaded yet.")
# You must check outside of the button press event if the session state has data to show it persistently.
if 'json_data' in st.session_state:
st.json(st.session_state['json_data'])
Despite the upload, the JSON content is not rendered. The issue persists with no error messages indicating what may be going wrong. Could you provide some guidance on how to troubleshoot or correct this problem so that the JSON data displays correctly after being uploaded?
Thank you for your assistance.