Search code examples
ipythonspotfire

IPython script runs on Spotfire Client, not Spotfire Web


I have the following python script (reduced, but the rest of it performs similar actions):

from Spotfire.Dxp.Application.Visuals import *
from Spotfire.Dxp.Data import *

#assign default values for prompts if needed
if Document.Properties['cannedKPISelected'].isspace():
    Document.Properties['cannedKPISelected'] = 'GS'
if Document.Properties['cannedTimeSelected'].isspace():
    Document.Properties['cannedTimeSelected'] = 'Month'

#determine which type of viz needs displayed based on a flag in the data
tableName='PrimaryDataTable'
columnToFetch='displayPercentageFlag'
activeTable=Document.Data.Tables[tableName]
rowCount = activeTable.RowCount
rowsToInclude = IndexSet(rowCount,True)
cursor1 = DataValueCursor.CreateFormatted(activeTable.Columns[columnToFetch])
for row in activeTable.GetRows(rowsToInclude,cursor1):
    rowIndex = row.Index
    percentageNeeded = cursor1.CurrentValue
    break

#create consumer report
for page in Document.Pages:
    for viz in page.Visuals:
        if str(viz.Id) == 'a7f5b4ec-f545-4d5f-a967-adec4c9fec79':
            if Document.Properties['coffeeReportSelected'] == 'Brand Category by Market':
                if Document.Properties['cannedKPISelected'] == 'GS' and Document.Properties['cannedTimeSelected'] == 'Month' and percentageNeeded == 'Y':
                    visualContentObject = viz.As[VisualContent]()
                    visualContentObject.MeasureAxis.Expression = 'Sum([GS Month]) as [GS Mnth]'
                    visualContentObject.RowAxis.Expression = '<[BRAND] as [Brand Category] NEST [MARKET] as [Market]>'
                    visualContentObject.ColumnAxis.Expression = '<[Axis.Default.Names] as [Measure Names]>'
                    visualContentObject.ShowColumnGrandTotal = True
                    visualContentObject.ShowColumnSubtotals = True
                    visualContentObject.ShowRowGrandTotal = False
                    visualContentObject.Title = 'Monthly GS by Brand, Market'
                    visualContentObject.Data.WhereClauseExpression = '[NAME] = "CANADA"'
                    visualContentObject.CellWidth = 125
                    Document.Properties['cannedReportHideRows'] = 'Sum(Abs(SN([GS Month],0)))'
                elif Document.Properties['cannedKPISelected'] == 'GS' and Document.Properties['cannedTimeSelected'] == 'Quarter' and percentageNeeded == 'Y':
                    visualContentObject = viz.As[VisualContent]()
                    visualContentObject.MeasureAxis.Expression = 'Sum([GS Quarter]) as [GS Qtr]'
                    visualContentObject.RowAxis.Expression = '<[BRAND] as [Brand] NEST [MARKET] as [Market]>'
                    visualContentObject.ColumnAxis.Expression = '<[Axis.Default.Names] as [Measure Names]>'
                    visualContentObject.ShowColumnGrandTotal = True
                    visualContentObject.ShowColumnSubtotals = True
                    visualContentObject.ShowRowGrandTotal = False
                    visualContentObject.Title = 'Quarterly GS by Brand, Market'
                    visualContentObject.Data.WhereClauseExpression = '[NAME] = "CANADA"'
                    visualContentObject.CellWidth = 125
                    Document.Properties['cannedReportHideRows'] = 'Sum(Abs(SN([GS Quarter],0)))'

So on and so forth.

This script (and others) run perfectly fine in the client. It does not run in the web. The web will say processing, then say ready (in the bottom left corner), all while doing nothing (no error, nothing). A few other scripts that I have in the same analysis run perfectly fine.

I know there are some limitations on IPython scripts on the web for security reasons, but I am only building a table. This cant be restricted can it? Web server logs are not capturing anything out of the ordinary.

We are on Spotfire 7.6

UPDATE: It seems to be due to this: if str(viz.Id) == 'a7f5b4ec-f545-4d5f-a967-adec4c9fec79':. This is because IDs are different between Web and Client unfortunately. Knowing my title changes as well, any ideas on what I could reference a visualization by that stays the same between client and web?


Solution

  • Because Spotfire changes IDs of a vis depending on whether it is on the web player vs the client, the script was not working as intended. I simply added the vis as a parameter instead of relying on the script to go and locate the correct vis. When the name of the vis changes, the parameter is updated correctly so it is still dynamic.