首页 > 解决方案 > How can I load and feed data from multiple excel/csv sheets into the mutliselect function? - Streamlit

问题描述

Context

In my web-app, I want my users to select different data categories and upon selecting this data category, it will load the data from its respective csv into the mutliselect function. The below demonstrates this:

Example enter image description here

So upon selection of social and Economy, load the respective data/columns from their separate excel sheets. Though I am lost on how to do this exactly.

I initially tried a for loop but it ended up creating many different multiselect columns. But this is not what I wanted. I just want the capability to load data from ‘economy’ if I click economy and if I select both ‘social’ and ‘economy’ that both datasets load. They are stored in different excel sheets.

My code as of now:

if choose_theme_category == 'Country specific':
        st.write("Choose data unique to a country for this theme.")
        Country_choice = st.beta_columns(3)
        countries = ['','United Kingdom', 'Ireland', 'Germany'] 
        Country = Country_choice[0].selectbox("Country", countries)    

  

    if Country == 'United Kingdom':
        # Category of data
        Category = st.beta_columns(4)
        Data_category = Category[0].checkbox("Social") 
        Data_category1 = Category[1].checkbox("Economy") 
        Data_category2 = Category[2].checkbox("Environment") 
        Data_category3 = Category[3].checkbox("Health") 
        Data_category4 = Category[0].checkbox("Policy") 
        
       # categories = [Data_category,Data_category1,Data_category2,Data_category3,Data_category4]
    
    data_mix_buttons = st.beta_columns([3,1,1])
    # confirmation_data = data_mix_buttons[0].button("Show Data")
    Hide_data = data_mix_buttons[2].checkbox("Hide Data")
    # if hide data is not pressed, then show data
    if not Hide_data:
        # for every selection chosen, add data from their respective excel sheets
        if Data_category:
            Select_data = st.multiselect("Choose columns", options=COVID_19_cols,key=1)
            Social_data = COVID_19_data[Select_data]
            if not Select_data:
                 st.error("Please select at least one column.")
            else:
                st.write(Social_data)

Is this possible? Any suggestions?

标签: pythonfilterstreamlit

解决方案


Solution is detailed here in the streamlit discussion website.


推荐阅读