Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

st.column_config.SelectboxColumn: Extend config with dict mapping to separate backend and user value representation. #6795

Open
robingie opened this issue Jun 4, 2023 · 3 comments
Labels
feature:st.column_config Related to column config functionalities type:enhancement Requests for feature enhancements or new features

Comments

@robingie
Copy link

robingie commented Jun 4, 2023

Problem

The current implementation of a select box is a great start but not always the data from the backend for the category options is the like the one for GUI. I'm missing a format function/option like in other widgets.

import pandas as pd
import streamlit as st

data_df = pd.DataFrame(
    {
        "category": [
            "📊 Data Exploration",
            "📈 Data Visualization",
            "🤖 LLM",
            "📊 Data Exploration",
        ],
    }
)

st.data_editor(
    data_df,
    column_config={
        "category": st.column_config.SelectboxColumn(
            "App Category",
            help="The category of the app",
            width="medium",
            options=[
                "📊 Data Exploration",
                "📈 Data Visualization",
                "🤖 LLM",
            ],
        )
    },
    hide_index=True,
)

Usually, options like this won't come from the backend directly and need to be converted before displaying them in the front end. I would really like to use a built-in solution for that, instead of formatting the panda's data frame before referencing it in the data editor as well as afterward to convert the users' selection back to the backend representation of the values.

Solution

A solution for that could be extending the config with a dictionary mapping to the user representation. In a way that it's just for display purposes.

import pandas as pd
import streamlit as st

data_df = pd.DataFrame(
    {
        "category": [
            "1",
            "2",
            "3",
            "4",
        ],
    }
)

st.data_editor(
    data_df,
    column_config={
        "category": st.column_config.SelectboxColumn(
            "App Category",
            help="The category of the app",
            width="medium",
            options={
                1:  "📊 Data Exploration",
                2:  "📈 Data Visualization",
                3:  "🤖 LLM",
            },
        )
    },
    hide_index=True,
)

Community voting on feature requests enables the Streamlit team to understand which features are most important to our users.

If you'd like the Streamlit team to prioritize this feature request, please use the 👍 (thumbs up emoji) reaction in response to the initial post.

@robingie robingie added the type:enhancement Requests for feature enhancements or new features label Jun 4, 2023
@CHerSun
Copy link

CHerSun commented Jun 4, 2023

format_func maybe? the same as everywhere else

@Scoodood
Copy link

Scoodood commented Jun 25, 2023

Great idea, please make the API more consistent with format_func

@zbjdonald
Copy link

Any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature:st.column_config Related to column config functionalities type:enhancement Requests for feature enhancements or new features
Projects
None yet
Development

No branches or pull requests

5 participants