Skip to content

FEEDBACK

Capture and save the results of a specified block over time. This block is almost always used in a LOOP. If the result is not found, it passes the result of the parent node. Params: referred_node : str The node ID to capture the result from. Returns: out : DataContainer The result of the specified node ID, or the result of the parent node if it was not found.
Python Code
from typing import Any, Optional

from flojoy import (
    DataContainer,
    JobResultBuilder,
    NodeReference,
    flojoy,
    get_job_result,
)


@flojoy
def FEEDBACK(
    referred_node: NodeReference,
    default: Optional[DataContainer] = None,
) -> Any:
    """Capture and save the results of a specified block over time. This block is almost always used in a LOOP.

    If the result is not found, it passes the result of the parent node.

    Parameters
    ----------
    referred_node : str
        The node ID to capture the result from.

    Returns
    -------
    DataContainer
        The result of the specified node ID, or the result of the parent node if it was not found.
    """

    result = get_job_result(referred_node.ref)
    if result:
        return result
    else:
        return (
            JobResultBuilder()
            .from_inputs([default] if default else [])
            .flow_to_directions(["default"])
            .build()
        )

Find this Flojoy Block on GitHub

Example

Having problems with this example app? Join our Discord community and we will help you out!
React Flow mini map

In this example, the LOOP node is used to iterate over an app multiple times, specifically 5 times.

Inside the LOOP body, we start by multiplying two CONSTANT nodes, 4 and 2, together. For subsequent iterations, we utilize FEEDBACK node. This node captures the result of multiplication of the two constants from the previous iteration and multiplies it to a CONSTANT node with a value of 2.

To visualize the sum, we employ the BIG_NUMBER node, which generates a plotly figure displaying a large number. The figure includes a relative delta, which represents the change relative to the previous iteration.