All,
I am trying to create a dynamic layout, but I keep running into a bug and I am unable to debug it. Any help would be appreciated:
import streamlit as st
import pandas as pd
def default_ui():
st.title("User Inputs")
user_n_files = st.sidebar.number_input(
label='# of files to read',
min_value=2
)
load_flag = st.sidebar.checkbox(
label='Load Browse Options',
value=False
)
return user_n_files, load_flag
def add_file_loading_options(n_files: int):
""" Add UI options for loading files
:param n_files: # of files user wants to load
"""
paths, field_1, field_2 = ([None] * n_files for k in range(3))
columns = list(st.beta_columns(n_files))
iteration_list = list(range(0, n_files))
for i in iteration_list:
with columns[i]:
st.header = f"""Select file {i + 1}"""
paths[i] = st.file_uploader(
label=f"""Browse to file {i + 1}""",
type='csv'
)
field_1[i] = int(
st.slider(
label=f'''Enter column number for field_1 in file {i + 1}''',
step=1,
format='%d'
)
)
field_2[i] = int(
st.slider(
label=f'''Enter column number for field_2 in file {i + 1}''',
step=1,
format='%d'
)
)
return paths, field_1, field_2
def main():
"""Central wrapper for controlling UI"""
st.header('Streamlit Testing')
n_files_to_read, flag = default_ui()
if flag:
paths, field_1, field_2 = add_file_loading_options(n_files_to_read)
option_flag = st.button(label='Run Tool')
if option_flag:
all_data = [
pd.read_csv(path) for path in paths
]
for df in all_data:
st.dataframe(df)
main()
Several things don’t work as expected. When ever a file is browsed and selected, I get the above error. It doesn’t even wait for the button to be clicked ? Any help is appreciated.
Thanks
Uday