filterironpythonspotfire

Spotfire Ironpython: Filters disappear after running a table through script?


I have a data table that I put into a script in a button. It takes the table and formats various visualizations on it, but after it goes through, the items in the filter bar on the right disappears and I get this error:

XmlHttpRequest failed. Internal Server Error Read error (-1): {"viewId":"ceb0fbf6-5bd1-4b3f-a191-a431f1ffaa0a","method":"InitializeFilter","args":"{"id":"97b12241-cb78-46c1-8b24-97cb789b34d2","filterContainerId":"poppedFilter11"}"} XMLHttpRequest: {"readyState":4,"responseText":"","status":500,"statusText":"Internal Server Error"}

This is my script:

from Spotfire.Dxp.Data import DataTableSaveSettings
from Spotfire.Dxp.Application.Visuals import ScatterPlot, BoxPlot
from Spotfire.Dxp.Application import Layout
page = Document.Pages.AddNew()

#visualization (I copy this for a total of 4 visualizations)

myVis = Document.ActivePageReference.Visuals.AddNew[ScatterPlot]()
myVis.Data.DataTableReference = input_table
myVis.Title = "Title"
myVis.XAxis.Expression = '\[Date\]'
myVis.YAxis.Expression = '\[Item1\]'
myVis.ColorAxis.Expression = '\[Item2\]'
myVis.YAxis.ManualZoom = True
myVis.LineConnection.ConnectionAxis.Expression = '\<\[Item3\]\>'
myVis.LineConnection.UseMarkerColor = True

#format

lst = []
for visual in page.Visuals:
lst.append(visual)
format = Layout.LayoutDefinition()
format.BeginStackedSection(1)
format.Add(lst\[0\])
format.Add(lst\[2\])
format.BeginSideBySideSection(1)
format.Add(lst\[1\])
format.Add(lst\[3\])
format.EndSection()
format.EndSection()

page.ApplyLayout(format)

In the table I have another column that I want to be able to filter by. When I open the table again, it looks like that other column has disappeared (it was unused in the visualizations). I'm thinking my script did something to the tables to wipe out all of the filters but I have no idea how to fix it


Solution

  • Your script throws errors.

    The page is created and the filter panel does look a bit iffy. However, this seems purely the effect of how you create the new page. The defaults must be not what one expects. If I add an AutoConfigure() and set the filter panel to visible, it looks better.

    I don't know what this extra column means, but now the script seems to work.

    from Spotfire.Dxp.Data import DataTableSaveSettings
    from Spotfire.Dxp.Application.Visuals import ScatterPlot, BoxPlot
    from Spotfire.Dxp.Application import Layout
    page = Document.Pages.AddNew()
    page.Title='My New Page'
    page.AutoConfigure()
    filter_panel=page.FilterPanel
    filter_panel.Visible=True
    
    #visualization (I copy this for a total of 4 visualizations)
    
    myVis = Document.ActivePageReference.Visuals.AddNew[ScatterPlot]()
    myVis.Data.DataTableReference = input_table
    myVis.Title = "Title1"
    myVis.XAxis.Expression = '[Date]'
    myVis.YAxis.Expression = '[Item1]'
    myVis.ColorAxis.Expression = '[Item2]'
    myVis.YAxis.ManualZoom = True
    myVis.LineConnection.ConnectionAxis.Expression = '<[Item3]>'
    myVis.LineConnection.UseMarkerColor = True
    
    myVis = Document.ActivePageReference.Visuals.AddNew[ScatterPlot]()
    myVis.Data.DataTableReference = input_table
    myVis.Title = "Title2"
    myVis.XAxis.Expression = '[Date]'
    myVis.YAxis.Expression = '[Item1]'
    myVis.ColorAxis.Expression = '[Item2]'
    myVis.YAxis.ManualZoom = True
    myVis.LineConnection.ConnectionAxis.Expression = '<[Item3]>'
    myVis.LineConnection.UseMarkerColor = True
    
    myVis = Document.ActivePageReference.Visuals.AddNew[ScatterPlot]()
    myVis.Data.DataTableReference = input_table
    myVis.Title = "Title3"
    myVis.XAxis.Expression = '[Date]'
    myVis.YAxis.Expression = '[Item1]'
    myVis.ColorAxis.Expression = '[Item2]'
    myVis.YAxis.ManualZoom = True
    myVis.LineConnection.ConnectionAxis.Expression = '<[Item3]>'
    myVis.LineConnection.UseMarkerColor = True
    
    myVis = Document.ActivePageReference.Visuals.AddNew[ScatterPlot]()
    myVis.Data.DataTableReference = input_table
    myVis.Title = "Title4"
    myVis.XAxis.Expression = '[Date]'
    myVis.YAxis.Expression = '[Item1]'
    myVis.ColorAxis.Expression = '[Item2]'
    myVis.YAxis.ManualZoom = True
    myVis.LineConnection.ConnectionAxis.Expression = '<[Item3]>'
    myVis.LineConnection.UseMarkerColor = True
    
    #format
    
    visuals = list(page.Visuals)
    format = Layout.LayoutDefinition()
    format.BeginStackedSection(1)
    format.Add(visuals[0])
    format.Add(visuals[2])
    format.BeginSideBySideSection(1)
    format.Add(visuals[1])
    format.Add(visuals[3])
    format.EndSection()
    format.EndSection()
    
    page.ApplyLayout(format)