我有以下python脚本(缩小,但其余部分执行类似的操作):
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)))'
等等。
这个脚本(和其他人)在客户端运行得很好。它不在网络上运行。网络会说处理,然后准备就绪(在左下角),一切都没有(没有错误,没有)。我在同一分析中使用的其他一些脚本运行得非常好。
我知道出于安全原因,网络上的IPython脚本存在一些限制,但我只是在构建一个表。这不能受限制吗? Web服务器日志没有捕获任何异常的东西。
我们在Spotfire 7.6上
更新:好像是由于:if str(viz.Id) == 'a7f5b4ec-f545-4d5f-a967-adec4c9fec79':
。这是因为遗憾的是,Web和Client之间的ID不同。知道我的标题也发生了变化,关于我可以引用可视化的任何想法在客户端和网络之间保持不变吗?
答案 0 :(得分:1)
因为Spotfire会更改vis的ID,具体取决于它是否在Web播放器与客户端之间,因此脚本无法正常工作。我只是将vis作为参数添加,而不是依靠脚本来找到正确的vis。当vis的名称发生变化时,参数会正确更新,因此它仍然是动态的。
答案 1 :(得分:0)
您能否弄清楚当前视觉效果的索引是什么,并以这种方式引用它?
尝试以下方法: 替换此行:
if str(viz.Id) == 'a7f5b4ec-f545-4d5f-a967-adec4c9fec79':
使用:
if viz[0] (or whatever the index is)
不确定这是否是您的想法,但我相信这将为您提供一种方法来参考可视化而无需使用ID。