Skip to content

plotly_dashboard

plotly_dashboard

Module for generating interactive Plotly dashboards from data products.

PlotlyDashboardGenerator

PlotlyDashboardGenerator(debug=False)

Class for generating interactive Plotly dashboards from data products.

This class provides a way to create interactive dashboards from trendify data products, similar to how the static matplotlib plots are generated, but with interactive features.

Initialize the dashboard generator.

Parameters:

Name Type Description Default
debug bool

Whether to enable debug logging

False
Source code in src/trendify/plotly_dashboard.py
def __init__(self, debug=False):
    """
    Initialize the dashboard generator.

    Args:
        debug (bool): Whether to enable debug logging
    """
    self.debug = debug
    self.app = dash.Dash(__name__, suppress_callback_exceptions=True)
    self.tag_data = {}
    self.color_maps = {}

debug_log

debug_log(message: str) -> None

Log debug messages if debug mode is enabled.

Source code in src/trendify/plotly_dashboard.py
def debug_log(self, message: str) -> None:
    """Log debug messages if debug mode is enabled."""
    if self.debug:
        print(f"[PY] {message}")

process_collection

process_collection(collection: DataProductCollection, title: str = 'Trendify Dashboard') -> Dash

Process collection of data products and generate a Plotly dashboard.

Parameters:

Name Type Description Default
collection DataProductCollection

Collection of data products to visualize

required
title str

Title for the dashboard

'Trendify Dashboard'

Returns:

Type Description
Dash

dash.Dash: The configured Dash application

Source code in src/trendify/plotly_dashboard.py
def process_collection(
        self,
        collection: DataProductCollection,
        title: str = "Trendify Dashboard"
    ) -> dash.Dash:
    """
    Process collection of data products and generate a Plotly dashboard.

    Args:
        collection (DataProductCollection): Collection of data products to visualize
        title (str): Title for the dashboard

    Returns:
        dash.Dash: The configured Dash application
    """
    self.debug_log(f"Processing collection with {len(collection.elements or [])} elements")

    # Get all tags in the collection
    all_tags = collection.get_tags()
    self.debug_log(f"Found {len(all_tags)} tags")

    # Process each tag's data products
    tab_contents = []
    for tag in all_tags:
        tag_str = str(tag)
        self.tag_data[tag_str] = {
            'tag': tag,
            'traces': collection.get_products(tag=tag, object_type=Trace2D).elements,
            'points': collection.get_products(tag=tag, object_type=Point2D).elements,
            'axlines': collection.get_products(tag=tag, object_type=AxLine).elements,
            'tables': collection.get_products(tag=tag, object_type=TableEntry).elements,
            'histograms': collection.get_products(tag=tag, object_type=HistogramEntry).elements,
        }

        # Create tab content for this tag
        tab_content = self._create_tab_content(tag_str)
        if tab_content:
            tab_contents.append({
                'label': tag_str,
                'value': tag_str,
                'content': tab_content
            })

    # Create the app layout
    self.app.layout = self._create_app_layout(title, tab_contents)

    # Register callbacks
    self._register_callbacks()

    return self.app

generate_plotly_dashboard

generate_plotly_dashboard(
    collection: DataProductCollection, title: str = "Trendify Dashboard", debug: bool = False
) -> Dash

Generate a Plotly dashboard from a data product collection.

This function creates an interactive dashboard that visualizes the data products in the collection, similar to how DataProductCollection.process_collection works with matplotlib, but with interactive Plotly features.

Parameters:

Name Type Description Default
collection DataProductCollection

Collection of data products to visualize

required
title str

Title for the dashboard

'Trendify Dashboard'
debug bool

Whether to enable debug logging

False

Returns:

Type Description
Dash

dash.Dash: The configured Dash application ready to run

Source code in src/trendify/plotly_dashboard.py
def generate_plotly_dashboard(
        collection: DataProductCollection,
        title: str = "Trendify Dashboard",
        debug: bool = False
    ) -> dash.Dash:
    """
    Generate a Plotly dashboard from a data product collection.

    This function creates an interactive dashboard that visualizes the data products
    in the collection, similar to how DataProductCollection.process_collection works
    with matplotlib, but with interactive Plotly features.

    Args:
        collection (DataProductCollection): Collection of data products to visualize
        title (str): Title for the dashboard
        debug (bool): Whether to enable debug logging

    Returns:
        dash.Dash: The configured Dash application ready to run
    """
    generator = PlotlyDashboardGenerator(debug=debug)
    return generator.process_collection(collection, title)