Adding a label to the st.selectbox

I have created a st.selectbox to select a pickle file for a model.
I created 5 variables to choose from, each variable representing a url to the pickle file.

Disaster, Economey, Health, Industry, Poverty = 'src/tasks/task-5-web-app-deployment/pckls/disaster.pkl', 'src/tasks/task-5-web-app-deployment/pckls/dweg.pkl', 'src/tasks/task-5-web-app-deployment/pckls/health.pkl', 'src/tasks/task-5-web-app-deployment/pckls/industry_II.pkl', 'src/tasks/task-5-web-app-deployment/pckls/poverty.pkl'

I then created the selectbox

option = st.selectbox(
            'Please Select the Pillar',
            options=(
                Disaster, Economey, Health, Industry, Poverty
                ), help='Here are 5 pillars that can influence the vulnerability of a City')

This is then loaded into the model

with open(option, 'rb') as file:
            kmeans = pkl.load(file)

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior:

Explain what you expect to happen when you run the code above.

Actual behavior:

Explain the undesired behavior or error you see when you run the code above.
If you’re seeing an error message, share the full contents of the error message here.

I then use the variable name to select the correct .csv file for the model and predictions.

I would like to be able to change what is seen in the options box to reflect the variable names not the variable values.

many thanks :slight_smile:

I would use a dictionary, here a quick extension of your code:

import streamlit as st

Disaster, Economy, Health, Industry, Poverty = 'src/tasks/task-5-web-app-deployment/pckls/disaster.pkl','src/tasks/task-5-web-app-deployment/pckls/dweg.pkl', 'src/tasks/task-5-web-app-deployment/pckls/health.pkl', 'src/tasks/task-5-web-app-deployment/pckls/industry_II.pkl', 'src/tasks/task-5-web-app-deployment/pckls/poverty.pkl'
# make a dictionary of the models
models = {'Disaster': Disaster, 'Economy': Economy,
        'Health': Health, 'Industry': Industry, 'Poverty': Poverty}
# give me the keys of the dictionary
model_names = models.keys()

option = st.selectbox(
    'Please Select the Pillar',
    options=model_names,
    help='Here are 5 pillars that can influence the vulnerability of a City')

st.info(models[option])

with open(models[option], 'rb') as file:
    kmeans = pkl.load(file)
1 Like

Great that works!

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