BIG_NUMBER
The BIG_NUMBER node generates a Plotly figure, displaying a big number with an optional prefix and suffix.Inputs
------
default : OrderedPair|Scalar|Vector
the DataContainer to be visualizedParams:relative_delta : boolwhether or not to show the relative delta from the last run along with big numbersuffix : strany suffix to show with big numberprefix : strany prefix to show with big numbertitle : strtitle of the plot, default = "BIG_NUMBER"Returns:out : Plotlythe DataContainer containing the Plotly big number visualization
Python Code
from flojoy import (
flojoy,
Plotly,
OrderedPair,
DefaultParams,
SmallMemory,
Scalar,
Vector,
)
from typing import cast
import plotly.graph_objects as go
from blocks.DATA.VISUALIZATION.template import plot_layout
MEMORY_KEY = "BIG_NUMBER_MEMORY_KEY"
@flojoy(inject_node_metadata=True)
def BIG_NUMBER(
default: OrderedPair | Scalar | Vector,
default_params: DefaultParams,
suffix: str,
prefix: str,
title: str,
relative_delta: bool = True,
scientific_notation: bool = False,
) -> Plotly:
"""The BIG_NUMBER node generates a Plotly figure, displaying a big number with an optional prefix and suffix.
Inputs
------
default : OrderedPair|Scalar|Vector
the DataContainer to be visualized
Parameters
----------
relative_delta : bool
whether or not to show the relative delta from the last run along with big number
suffix : str
any suffix to show with big number
prefix : str
any prefix to show with big number
title : str
title of the plot, default = "BIG_NUMBER"
Returns
-------
Plotly
the DataContainer containing the Plotly big number visualization
"""
job_id = default_params.job_id
node_name = __name__.split(".")[-1]
layout = plot_layout(title=title if title else node_name)
fig = go.Figure(layout=layout)
prev_num = cast(str, SmallMemory().read_memory(job_id, MEMORY_KEY))
match default:
case OrderedPair():
big_num = default.y[-1]
case Scalar():
big_num = default.c
case Vector():
big_num = default.v[-1]
case _:
raise ValueError(f"Invalid input type {type(default)} for node {node_name}")
delta_val_format = ".1%" if relative_delta is True else ".1f"
val_format = "%g" if scientific_notation is False else ".4e"
fig.add_trace(
go.Indicator(
mode="number+delta",
value=big_num,
domain={"y": [0, 1], "x": [0, 1]},
number={"prefix": prefix, "suffix": suffix, "valueformat": val_format},
delta=None
if prev_num is None
else {
"reference": float(prev_num),
"relative": relative_delta,
"valueformat": delta_val_format,
},
)
)
SmallMemory().write_to_memory(job_id, MEMORY_KEY, str(float(big_num)))
return Plotly(fig=fig)
Example
Having problem with this example app? Join our Discord community and we will help you out!
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 a special node called FEEDBACK
. 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.