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

experimental_data_editor selectbox support #6194

Closed
NusretOzates opened this issue Feb 27, 2023 · 5 comments
Closed

experimental_data_editor selectbox support #6194

NusretOzates opened this issue Feb 27, 2023 · 5 comments
Labels
type:enhancement Requests for feature enhancements or new features

Comments

@NusretOzates
Copy link

NusretOzates commented Feb 27, 2023

Problem

I'm trying to create a personal data editing tool to edit my labeled NER dataset of mine. Before the data editor, I was using text_area but the data editor is a much better solution. So I have 2 columns, token, and tag, for the tag I have options like B-PER I-PER, etc.

To edit the dataframe I have to delete the B-PER text and replace it with I-PER. But the problem is I'm a lazy person.

Solution

Can we somehow add a select box for every row? Currently, it is not possible because streamlit.selectbox creates the boxes instantly outside of the editor

Additional context

This is what I have:

image


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.

@NusretOzates NusretOzates added the type:enhancement Requests for feature enhancements or new features label Feb 27, 2023
@johalnes
Copy link

Second this!
I actually do think it's supported already, and all that is missing is documentation about columns specifications.

By specificing a columns as category one get the selectbox:

import streamlit as st
import pandas as pd

df = pd.DataFrame(
    [
       {"command": "st.selectbox", "rating": 4, "is_widget": True},
       {"command": "st.balloons", "rating": 5, "is_widget": False},
       {"command": "st.time_input", "rating": 3, "is_widget": True},
   ]
)
df["command_as_category"] = df["command"].astype("category")
edited_df = st.experimental_data_editor(df)

favorite_command = edited_df.loc[edited_df["rating"].idxmax()]["command"]
st.markdown(f"Your favorite command is **{favorite_command}** 🎈")

What I miss is to add possible values within this selectbox. Can someone tell if this is possible within the current streamlit version?

@jrieke
Copy link
Collaborator

jrieke commented Feb 27, 2023

Yes, this is already possible, see the comment above! Agree that we need to document it better (cc @snehankekre). There's no way to specify options right now but this will be possible as part of column config, which we plan to release in the next few months. You can see updates at https://roadmap.streamlit.app/

Closing this since it's already possible.

@jrieke jrieke closed this as completed Feb 27, 2023
@LukasMasuch
Copy link
Collaborator

LukasMasuch commented Feb 27, 2023

There is a way to add additional categories to the selection via add_categories. For example:

import pandas as pd
import streamlit as st

df = pd.DataFrame(
    [
        {"command": "st.selectbox", "rating": 4, "is_widget": True},
        {"command": "st.balloons", "rating": 5, "is_widget": False},
        {"command": "st.time_input", "rating": 3, "is_widget": True},
    ]
)
df["command_as_category"] = (
    df["command"].astype("category").cat.add_categories(["st.button", "st.radio"])
)

edited_df = st.experimental_data_editor(df)

favorite_command = edited_df.loc[edited_df["rating"].idxmax()]["command"]
st.markdown(f"Your favorite command is **{favorite_command}** 🎈")

@NusretOzates
Copy link
Author

I tried it and it works very nicely thanks a lot for this feature!

@johalnes
Copy link

Nice @LukasMasuch!
Didn't know of that one, and now everything I'm currently doing in aggrid can be changed with data_editor😄

Thanks for responding and great work!

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

No branches or pull requests

4 participants