Skip to content

FolderInput

Bases: InputElement

_value_type: type property

Get the FolderInput value type: a single string str.

value: Optional[str] property

Returns:

Type Description
Optional[str]

The path or list of paths for the selected folder: if paths are not absolute, then

Optional[str]

they are considered relative to the data root folder. See

Optional[str]

Best Practices With Data for more information.

__init__(key, value, label=None, count=None, optional=False, hide_when_disabled=False, kwargs)

A single folder 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 _. Try to choose a key that is meaningful for your context (see examples projects).

required
value Optional[Union[str, List[str]]]

Path to folder. Provided folder doesn't necessarily have to exist for the Streamlit mode, however its existence will be checked at execution time. If path is not absolute, then it is 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 folder 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 count is defined, the expected value should always be a list, even if the count is 1. count can either be a fixed number (e.g. 3) or an expression dependent of other elements (see Using Expressions for more information).

None
optional Union[bool, str]

Specify whether the value may be None. optional can either be a fixed boolean (False or True) or a conditional expression dependent of other elements (see Using Expressions for more information).

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
**kwargs Any

Extra user meta-data to attach to the element. Argument names cannot overwrite existing attributes or methods name such as streamlit, _value, etc.

{}

Raises:

Type Description
ValueError

if the key is empty or starts with _.

AttributeError

if one the kwargs conflicts with an existing attribute or method.

Example

from onecode import folder_input, Mode, Project

Project().mode = Mode.EXECUTE
widget = folder_input(
    key="FolderInput",
    value="/path/to/"
)
print(widget)
Output
"/path/to/"

_validate(value)

Raises:

Type Description
FileNotFoundError

if the path does not exist or is not a folder.

imports() staticmethod

Returns:

Type Description
List[str]

Python import statements required by the Streamlit code.

init() staticmethod

Returns:

Type Description
str

The Python statements that must be initialized before being used by the Streamlit code.

streamlit(id)

Returns:

Type Description
str

The Streamlit code for a folder selection (st.text_input for the path combined with a

str

tkinter.filedialog.askdirectory for the file selection).