- Are you building projects for users who aren’t familiar with Spotfire’s concept of panels?
- Would you like to be able to turn panels on and off with the click of a button?
- Do you want to learn a little bit more about IronPython?
This week, I am sharing a bit of code that I’ve used for years in almost every project I build. It is easy to use IronPython to turn panels on and off. It is especially useful when…
- Building projects for people who aren’t familiar with Spotfire controls
- Building for the web player
- Space is tight and I want to be able to quickly and easily turn panels on and off
You might be wondering why this code would be useful for the web player. Well, web player users don’t have the ability to toggle all panels on and off. As shown below, web player users only have access to the Filter Panel and the Bookmarks Panel.
Here is the code in Spotfire. I always take a screenshot because the copy and paste sometimes corrupts spacing.
And here is a code snippet that you can copy and paste. Adjust indents accordingly.
if (Document.ActivePageReference.FilterPanel.Visible == False):
Document.ActivePageReference.FilterPanel.Visible = True
Document.ActivePageReference.FilterPanel.Visible = False
Steps to Implement Code
- Add a Text Area
- Right-click, select Edit HTML
- Click the insert Action Control button
- Type in a name for the button, such as “Show Hide Details on Demand”
- Click the Script button
- Name the script.
- Copy and paste the script.
- Click Run to test. (No paramters required).
And you’re done!
Modifying for Different Panels
The code snipppet shown above will work for the Details on Demand Panel. To modify it for the Filter Panel, substitute “DetailsOnDemand” for “Filter”. To modify it for the Data Panel, you will need different code. See below.
from Spotfire.Dxp.Application import Panel
from Spotfire.Dxp.Application.Layout import PanelState as ps
for panel in Document.ActivePageReference.Panels:
if (panel.TypeId.DisplayName == “Data”):
if (panel.Visible == True):
elif (panel.Visible == False):
panel.PanelState = ps.Docked
If you want to explore other panels, check out the API reference here (note, this is the 7.14 reference).
If You Liked This Try
- IronPython to Sort Bars of a Combination Chart`
- Turn Labels On and Off With IronPython
- IronPython to Reset Tags
Content created with Spotfire version 7.12.
Guest Spotfire blogger residing in Whitefish, MT. Working for SM Energy’s Advanced Analytics and Emerging Technology team!