streamlit-pydantic icon indicating copy to clipboard operation
streamlit-pydantic copied to clipboard

Handle Collection Type fields

Open papalotis opened this issue 3 years ago • 7 comments

Feature description: Correctly handle fields such as List[str]

Curently when a field is of a collection type such as dict, list, Mapping, Sequence etc. the behaviour is broken. For the model

class ExampleModel(BaseModel):
        text: str
        many_texts: Sequence[str]

the output is broken image and pressing the submit button results in the following error Whoops! There were some problems with your input: many_texts: field required

Problem and motivation:

I have forms where some of the inputs are an arbitrary number of strings. Up until now I have solved this with a text_area widget, and prompt the user to separate their inputs with commas. Then with a custom validator the strings can be put back into a list. While this kinda works, it is a very hacky solution, it prevents me from using this package without breaking up my model

Is this something you're interested in working on?

Currently I don't have the capacity but it is something that am willing to look into in the near future (in a couple of months)

papalotis avatar Oct 01 '21 01:10 papalotis

Also add Key or Values of Dicts for the Option values instead of enum's only.

ChrisDelClea avatar Oct 28 '21 17:10 ChrisDelClea

@papalotis Thanks for your feature suggestion. This is indeed broken when it is used with pydantic_form (instead of pydantic_input). The problem is that Streamlit currently does not provide any kind of input element that supports string lists. Streamlit supports list input only with the multiselect and the file_uploader widgets, but this does not help with string lists. Therefore, I had to combine multiple widget to support list inputs. However, this does not work within forms, since forms do not support interactive elements :(

One solution for that might be to use custom streamlit widgets (e.g. streamlit-tags), but I have to evaluate if that works with forms.

lukasmasuch avatar Nov 02 '21 22:11 lukasmasuch

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 14 days

github-actions[bot] avatar Feb 01 '22 02:02 github-actions[bot]

@LukasMasuch Just wanted to bump this as I am running into the issue as well. Any thoughts on a solution or workaround? I'd be happy to try to help contribute if you have ideas.

Great package btw!

disbr007 avatar Feb 08 '22 17:02 disbr007

@disbr007 Thanks for your comment! There is no good workaround I know of at the moment since streamlit does not provide any widgets for multi-element inputs. But there might be a solution for this soon :)

lukasmasuch avatar Feb 09 '22 22:02 lukasmasuch

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 14 days

github-actions[bot] avatar May 11 '22 02:05 github-actions[bot]

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 14 days

github-actions[bot] avatar Aug 10 '22 02:08 github-actions[bot]

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 14 days

github-actions[bot] avatar Nov 09 '22 02:11 github-actions[bot]