Introduction
This article provides an example of dynamically laying out a dashboard based on predefined Spotfire visuals using IronPython. Its uses a combination fo the Spotfire Layout API as well as Spotfire's ability to hide page tabs and copy content like visuals and text areas between page tabs. Several examples of where this may be beneficial is where security might control what content a user should see or potentially where the data values might determine which visuals are of more importance. The attached DXP example use a simple property control to determine which visuals and in which order they should be layed out on the page. It deletes everything but the Text Area on the Dynamic Page tab and copies visuals from the Source Visuals tab based on the values in the Input Text box. You could also use IronPython to dynamically drive this values through a data query also.
IronPython Code
from Spotfire.Dxp.Application.Layout import LayoutDefinition # Remove all visuals but the text area # This should be customized depending on how your application "starts". for viz in Document.ActivePageReference.Visuals: if viz.Title != 'TEXTAREA': Document.ActivePageReference.Visuals.Remove(viz) else: inputTextArea = viz # Parse property control to get list of visuals to copy and add to current page. # All visuals are copied from the "Source Visuals" tab but this could span more than 1 tab visualList = Document.Properties['visualList'] for vizTitle in visualList.split(','): for page in Document.Pages: if page.Title == 'Source Visuals': for visual in page.Visuals: if visual.Title == vizTitle: Document.ActivePageReference.Visuals.AddDuplicate(visual) # Layout all visuals on page, text area on top, other visuals side by side. page = Document.ActivePageReference layout = LayoutDefinition() layout.BeginStackedSection() layout.Add(inputTextArea,15) layout.BeginSideBySideSection(85) for vidx in Document.ActivePageReference.Visuals: print vidx.Title if vidx.Title != 'TEXTAREA': layout.Add(vidx) layout.EndSection() layout.EndSection() page.ApplyLayout(layout)
Attachments
Download Attachment from resources.
dynamic_dashboard_page_example.dxp
Recommended Comments
There are no comments to display.