NameError: name 'data' is not defined

I am new to streamlit, when i click checkbox the above error message appears, code is given which is the small part of application, the only problem i am facing, the data loading is ok.

import streamlit as st
import pandas as pd

tablist =["Web Data","Explore Data"]
t1,t2= st.tabs(tablist)


with t1:
    with st.form("web_form"):
        url = st.text_input("Enter URL")
        ok = st.form_submit_button("OK")
if(ok):
    data = pd.read_csv(url,header=None)
    st.write("Loaded")

with t2:
    fs = st.checkbox("File Statistics")
    fd = st.checkbox("File Data")
    if(fs):
        st.write(data.describe())
    if(fd):
        st.write(data)

Hi @fmkundi! Please remember that streamlit runs the whole code from top to bottom on each interaction. The data is no longer in memory after you click the checkbox. Try to use session state to store the data value st.session_state.data

Thanks
Now it works

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.