Skip to content

TABLE

Create a Plotly Table visualization for a given input DataContainer.Params:default : OrderedTriple|OrderedPair|DataFrame|Vector|Scalarthe DataContainer to be visualizedReturns:out : Plotlythe DataContainer containing the Plotly Table visualization
Python Code
import pandas as pd
import plotly.graph_objects as go
from flojoy import DataFrame, OrderedPair, OrderedTriple, Plotly, Scalar, Vector, flojoy
from blocks.DATA.VISUALIZATION.template import plot_layout


@flojoy
def TABLE(default: OrderedTriple | OrderedPair | DataFrame | Vector) -> Plotly:
    """Create a Plotly Table visualization for a given input DataContainer.

    Parameters
    ----------
    default : OrderedTriple|OrderedPair|DataFrame|Vector|Scalar
        the DataContainer to be visualized

    Returns
    -------
    Plotly
        the DataContainer containing the Plotly Table visualization
    """

    layout = plot_layout(title="TABLE")
    fig = go.Figure(layout=layout)

    match default:
        case OrderedPair():
            x = default.x
            y = default.y
            fig.add_trace(
                go.Table(
                    header=dict(values=["x", "y"], align="center"),
                    cells=dict(values=[x, y], align="center"),
                )
            )
        case OrderedTriple():
            x = default.x
            y = default.y
            z = default.z
            fig.add_trace(
                go.Table(
                    header=dict(values=["x", "y", "z"], align="center"),
                    cells=dict(values=[x, y, z], align="center"),
                )
            )
        case Vector():
            v = default.v
            fig.add_trace(
                go.Table(
                    header=dict(values=["v"], align="center"),
                    cells=dict(values=[v], align="center"),
                )
            )
        case Scalar():
            c = default.c
            fig.add_trace(
                go.Table(
                    header=dict(
                        values=["Scalar"],
                        align="center",
                        font=dict(size=1),
                        height=0,
                    ),
                    cells=dict(
                        values=[[c]],
                        align="center",
                        font=dict(size=25),
                    ),
                )
            )
        case DataFrame():
            df = pd.DataFrame(default.m)
            fig.add_trace(
                go.Table(
                    header=dict(values=list(df.columns), align="center"),
                    cells=dict(
                        values=[df[col] for col in df.columns],
                        align="center",
                    ),
                )
            )
    return Plotly(fig=fig)

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, we start by using the LINSPACE node to generate a Vector object of the DataContainer class.

Next, we employ the PLOTLY_DATASET node to create a DataFrame object of the DataContainer class.

To convert the DataFrame into an OrderedTriple object of the DataContainer class, we utilize the DF_2_ORDEREDTRIPLE node. The resulting OrderedTriple object contains three arrays: x, y, and z.

Finally, we visualize the data from these three nodes using the TABLE node, which generates a Plotly Table visualization for each of the input nodes.