Jump to content
  • How to find what visualizations referencing each data table in Spotfire® using IronPython


    This article provides code samples of how to find what visualizations referencing each data table in Spotfire® using IronPython

    Introduction

    The following IronPython scripts loops all data tables in an analysis and finds all referencing visualizations. This can be useful to see where the data tables are used, and perhaps find unused data tables.

    Code Samples

    # Copyright © 2021. TIBCO Software Inc.  Licensed under TIBCO BSD-style license.
    
    from Spotfire.Dxp.Application.Visuals import Visualization
    
    for dataTable in Document.Data.Tables:
    	result = [];
    	for page in Document.Pages:
    		for vis in page.Visuals:
    			visualization = vis.As[Visualization]()
    			if visualization != None and visualization.Data.DataTableReference == dataTable:
    				result.append(visualization.Title);
    	print(dataTable.Name + ':' + ','.join(result));
     

    The script generates a printout like this:

     data table 1: visualization 1, visualization 2
     data table 2: visualization 1
     data table 3:
     

    With a slight modification the script can be used with the Application Profiler tool in Spotfire Analyst to add an extra "visualizations" column to the "DataTables" result file. Note: in this case the script will be called by the Application Profiler runtime for each data table (with the argument "DataTable"), so we don't loop the data tables in the script. For more information about how to use Application Profiler, see the Spotfire Analyst User's Guide.

    # Copyright © 2021. TIBCO Software Inc.  Licensed under TIBCO BSD-style license.
    
    from Spotfire.Dxp.Application.Visuals import Visualization
    
    result = [];
    for page in Application.Document.Pages:
    	for vis in page.Visuals:
    		visualization = vis.As[Visualization]()
    		if visualization != None and visualization.Data.DataTableReference == DataTable:
    			result.append(visualization.Title);
    OutputColumns["Visualizations"] = ','.join(result);
     

    You also need an extra script to add the "Visualizations" output column:

    from System import Tuple, String
    from Spotfire.Dxp.Data import DataType
    
    OutputColumnDataTypes.Add(Tuple.Create[String,DataType]("Visualizations", DataType.String))
     

    Here is how it looks like in the Application Profiler UI:

    applicationprofiler.thumb.png.184eae604d8be05a4b0fc11b24e2314f.png


    The result is put in the added "Visualizations" column in the DataTables table:
     

    datatables.thumb.png.cbdc58b13d567d739b5f0d5df2496e64.png


    License:  TIBCO BSD-Style License

     

     

    • Like 1

    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...