Jump to content
  • How to find what data table is used by each visualization in Spotfire® using IronPython


    This article provides code snippet of how to find what data table is used by each visualization in Spotfire® using IronPython

    Introduction

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

    Code Samples

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

    The script generates a printout like this:

    Population Change by Region, World Bank Data

    Largest 10 Countries by Population, World Bank Data

    Map Chart, Another data table

    With a slight modification the script can be used with the Application Profiler tool in Spotfire Analyst to add an extra "Data Table" column to the "Visualizations" result file. Note: in this case the script will be called by the Application Profiler runtime for each visualization (with the argument "Visual"), so we don't loop the visualizations 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
    
    visual = Visual.As[Visualization]()
    
    if visual != None:
    	OutputColumns["Data Table"] = visualization.Data.DataTableReference.Name
     

    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]("Data Table", DataType.String)) 
     

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

    app_profiler.png.b6c9da4ba0f3731001531f11e5c042f9.png

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

    result_3.thumb.png.70f5078d6c255dee59b69dbb9305a2a5.png

    License:  TIBCO BSD-Style License

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...