gagan3012 / streamlit-tags

Custom Tag component for streamlit
https://streamlit-tags.readthedocs.io/en/latest/
MIT License
281 stars 17 forks source link

Add containers external writing support #40

Open Rom1deTroyes opened 1 year ago

Rom1deTroyes commented 1 year ago

Is your feature request related to a problem? Please describe.

When using containers as a variable to be able to write into from outside the container (i.e. not with st.container: but cont = st.container() + cont.write('...')) it is not possible to attach a st_tag component.

Describe the solution you'd like

Having a way to do st.st_tag, cont.st_tag and so on, like the other Streamlit input widgets.

Describe alternatives you've considered

I've tried forms and expanders like in #35 and #36 : they render well, but they are not writable from the outside, and cannot be intrigued like I need (container in a container, writing from a function in another place).

Additional context

I can confirm that it works with with:

    with st.container():
        st.header("HeaderC")
        st.markdown("-----")

        selection_codes_articles = st_tags(
                label="Articles à chercher C:",
                text="(Code + Entrée pour ajouter)",
                value=["12345-01"],
                suggestions=["12345-01"],
                maxtags=-1,
                key="ArticlesC",
        )
        btn = st.button('->C')

image

But it didn't work when writing from outside (see the second example in documentation) :

    cont = st.container()
    cont.header("HeaderCont")
    cont.markdown("-----")
    selection_codes_articles = st_tags(
            label="Articles à chercher Cont:",
            text="(Code + Entrée pour ajouter)",
            value=["12345-01"],
            suggestions=["12345-01"],
            maxtags=-1,
            key="ArticlesCont",
    )
    btn = cont.button('->Cont')

image

The st_tag() is not internal, so it is rendered after the container (expected behavior, thus we need a way to attach the component inside the container).

Using cont.st_tags of course don't work either (StreamlitAPIException: st_tags() is not a valid Streamlit command.), but will be the best option (please @streamlit gets this widget official !)

Any thoughts about how to achieve this ?

Thanx for this works, it's a great piece of UI/UX 🥇

CHerSun commented 1 year ago
with cont:
   st_tags...

???

And how do you expect to add writing to st.container directly, if author doesn't influence Streamlit internal code? It's not C# with extension methods