Spotfire 使用IronPython脚本

本文介绍了一系列使用IronPython和JavaScript在Spotfire中的实用脚本技巧,包括检查数据表链接状态、获取用户名、验证服务器连接、存储用户凭据、禁用手柄及控制轴选择器可见性等。
部署运行你感兴趣的模型镜像

脚本位置:文件->文档属性,新建即可。

1、使用IronPython检查数据表是链接到源还是嵌入在Spotfire中

from Spotfire.Dxp.Data import *

table=Document.Data.Tables["表名"]

found,tableSettings=Application.Document.Data.SaveSettings.TryGetDataTableSettings(table.Id);
if found and not tableSettings.UseLinkedData :
	print "Table is embedded"
else:
	print "Table is Linked"

2、使用IronPython获取登录的Spotfire和Windows用户名

from System import Environment, Threading, Security

#This script assumes you have a document property called "myProperty" and will populate the property with the output.
# 需要定义 myProperty 属性
Document.Properties["myProperty"]  ="\nSpotfire Username: " + Threading.Thread.CurrentPrincipal.Identity.Name
Document.Properties["myProperty"] +="\nWindows Username(Env): " + Environment.UserName
Document.Properties["myProperty"] +="\nWindows Username(WinIdent): " + Security.Principal.WindowsIdentity.GetCurrent().Name

3、验证是否连接服务器

from Spotfire.Dxp.Framework.ApplicationModel import ConnectivityService

connectivity= Application.GetService[ConnectivityService]()
# In 10.4+
#Document.Properties["myProperty"]  ="Public Server URI: " + str(connectivity.ServerPublicUri)
#Document.Properties["myProperty"]  +="\nInternal Server URI: " + str(connectivity.ServerInternalUri)

# Obsolete, but still availiable
Document.Properties["myProperty"]  ="Server: " + str(connectivity.ServerUri)

Document.Properties["myProperty"] += "\nConnected: " + str(connectivity.IsOnline)

4、使用CredentialsService存储当前用户的凭据

在用户会话结束之前(通常在关闭应用程序或Web浏览器时),设置凭据才可用。这些凭据存储在内存中,并且可以在用户会话中的任何后续脚本或其他外部API调用中使用。

from Spotfire.Dxp.Framework.ApplicationModel import CredentialsService
from System.Threading import Thread 

credService = Application.GetService(CredentialsService)

#Store the username and map it with the key myuser
credService.SetCredentials[str]('myuser',Thread.CurrentPrincipal.Identity.Name)

#Get the currentuser
if credService.HasCredentials("myuser"): 
 currentuser=credService.TryGetCredentials[str]('myuser')

#To Remove Credential key
credService.RemoveCredentials("myuser")

#Now this key can be accessed in any other python script using #credService.TryGetCredentials[str]('myuser') 
#and does not need to be stored in a document property.

5、使用JavaScript禁用Spotfire中的左右手柄

$( document ).ready(function(){
    setTimeout(function(){
        // Unbind() method removes event handlers from selected elements.
        $(".Handle.sf-element.sf-element-thumb.TouchTarget").unbind()
    }, 3000);
}) 

6、在可视化中打开/关闭轴选择器

from Spotfire.Dxp.Application.Visuals import VisualContent

# 1、[Spotfire.Dxp.Application.Visuals.ScatterPlot]
visual = myvis.As[VisualContent]()
# x轴
if(visual.XAxis.ShowAxisSelector==True):
    visual.XAxis.ShowAxisSelector = False
else:
    visual.XAxis.ShowAxisSelector = True
# y轴
if(visual.YAxis.ShowAxisSelector==True):
    visual.YAxis.ShowAxisSelector = False
else:
    visual.YAxis.ShowAxisSelector = True

#'myvis' is a script parameter of type 'Visualization'.

# 2、[Spotfire.Dxp.Application.Visuals.HtmlTextArea] 中不可用,没有x,y轴

# 3、[Spotfire.Dxp.Application.Visuals.CrossTablePlot]
vi = myvi.As[VisualContent]()
print vi
# print vi.RowAxis
if(vi.ShowAxisSelectors==True):
	vi.ShowAxisSelectors = False
else:
	vi.ShowAxisSelectors = True

7、显示或隐藏页面

以编程方式在查看模式下向消费者用户显示或隐藏页面。这意味着可以根据打开分析的上下文(例如,登录用户是谁)向消费者用户显示或隐藏页面。

for p in Document.Pages:
	if p.Title=='Intro':
		if p.Visible == False:
			p.Visible = True
		else:
			p.Visible = False 

 

您可能感兴趣的与本文相关的镜像

Python3.9

Python3.9

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

种麦南山下

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值