Skip to content

ImageOutput

Bases: OutputElement

value: str property

Returns:

Type Description
str

The path or list of paths for the output file(s): if paths are not absolute, then

str

they are considered relative to the data output folder. See

str

Best Practices With Data for more information.

__init__(key, value, label=None, tags=None)

An image as part of the image carousel.

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 str

Path to the output image file which must have a .jpg, .jpeg, .png or .svg extension. Unless absolute, a path is relative to the outputs folder of the flow currently running.

required
label Optional[str]

Typically to be used by Streamlit for display purpose only. If not defined, it will default to the key.

None
tags Optional[List[str]]

Optional meta-data information about the expected file. This information is only used when the JSON output attributes are written to the output manifest.

None

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 image_output, Mode, Project

Project().mode = Mode.CONSOLE
widget = image_output(
    key="ImageOutput",
    value="/path/to/file.jpg",
    label="My ImageOutput",
    tags=['Image']
)
print(widget)
Output
"/path/to/file.jpg"

_validate(value)

Raises:

Type Description
ValueError

if the file does not have an image-like extension, i-e: .jpg, .jpeg, .png, .svg.

streamlit() staticmethod

Returns:

Type Description
str

The Streamlit code to show an image as part of the image carousel.

Tip

A static function _show_img(filepath: str) is available for any Streamlit code to use. It will automatically add the given image to the carousel without you needing to deal with the carousel.