FileInput¶
Bases: InputElement
_value_type: type
property
¶
Get the FileInput value type: either a list of string list[str]
when the
FileInput is multiple file selection, otherwise a single string str
.
value: Optional[Union[List[str], str]]
property
¶
Returns:
Type | Description |
---|---|
Optional[Union[List[str], str]]
|
The path or list of paths for the selected file(s): if paths are not absolute, then |
Optional[Union[List[str], str]]
|
they are considered relative to the data root folder. See |
Optional[Union[List[str], str]]
|
Best Practices With Data for more information. |
__init__(key, value, label=None, count=None, optional=False, hide_when_disabled=False, types=None, multiple=False, tags=None)
¶
A single or multiple file selector.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key |
str
|
ID of the element. It must be unique as it is the key used to story data in
Project(), otherwise it will lead to conflicts at runtime in both execution and
Streamlit modes. The key will be transformed into snake case and slugified to avoid
any special character or whitespace. Note that an ID cannot start with |
required |
value |
Optional[Union[str, List[str], List[List[str]]]]
|
Path to file(s). Provided file(s) don't necessarily have to exist for the Streamlit mode, however their existence will be checked at execution time. If paths are not absolute, then they are considered relative to the data root folder. See Best Practices With Data for more information. |
required |
label |
Optional[str]
|
Label to display left of the file selector. |
None
|
count |
Optional[Union[int, str]]
|
Specify the number of occurence of the widget. OneCode typically uses it for the
streamlit case. Note that if |
None
|
optional |
Union[bool, str]
|
Specify whether the value may be None. |
False
|
hide_when_disabled |
bool
|
If element is optional, set it to True to hide it from the interface, otherwise it will be shown disabled. |
False
|
types |
List[Tuple[str, str]]
|
List of filters allowing to narrow file selection within Streamlit. Each filter
must be a pair of (name, list of allowed extensions), e.g.
|
None
|
multiple |
bool
|
Set to True if multiple choice is allowed, otherwise only a single element can be selected. |
False
|
tags |
Optional[List[str]]
|
Optional meta-data information about the expected file. This information is only
used by the |
None
|
Raises:
Type | Description |
---|---|
ValueError
|
if the |
AttributeError
|
if one the |
Example
from onecode import file_input, Mode, Project
Project().mode = Mode.EXECUTE
widget = file_input(
key="FileInput",
value=["/path/to/file1.txt", "/path/to/file2.csv"],
multiple=True,
tags=['MyTags']
)
print(widget)
["/path/to/file1.txt", "/path/to/file2.csv"]
_validate(value)
¶
Validate the selected value (see _validate_option_value()). In case of multipe file selection, each choice is validated individually.
_validate_file_value(value)
¶
Raises:
Type | Description |
---|---|
FileNotFoundError
|
if the path does not exist or is not a file. |
streamlit(id)
¶
Returns:
Type | Description |
---|---|
str
|
The Streamlit code for a file selection ( |
str
|
|