【问题标题】:Is there a way to get user input appended to a table in spotfire?有没有办法让用户输入附加到spotfire中的表格?
【发布时间】:2020-09-15 16:32:12
【问题描述】:

我有一个表 Table1 在 spotfire (dcube) 中包含一些上下文信息,其中包含:

Name      Food    Seating
XYZ     Seafood   outdoors

我创建了一个带有两个按钮YesNo 的测试区域。 用户将在Table1 中选择一条记录并单击其中一个按钮,它应该使用添加的列Preference 填充另一个表Table2,输出如下:

Name      Food    Seating   Preference
XYZ     Seafood   outdoor     Yes

preference 列的值根据用户是点击了Yes 还是No 来填充。当用户在Table1 中设置另一条记录的偏好时,它应该在Table2 中附加为一行。

在不使用 TERR 的情况下,这是否可以通过 R 或 IronPython 实现?

【问题讨论】:

    标签: r ironpython spotfire spotfire-webplayer


    【解决方案1】:

    您可以使用 python 并写回数据库来实现此目的。但是我不确定没有外部数据源的好/有效的方法。

    from Spotfire.Dxp.Data.Import import DatabaseDataSource
    from Spotfire.Dxp.Data.Import import DatabaseDataSourceSettings
    from Spotfire.Dxp.Application.Visuals import TablePlot
    from Spotfire.Dxp.Application.Visuals import VisualTypeIdentifiers
    from Spotfire.Dxp.Data import IndexSet
    from Spotfire.Dxp.Data import RowSelection
    from Spotfire.Dxp.Data import DataValueCursor
    from Spotfire.Dxp.Data import DataSelection
    from Spotfire.Dxp.Data import DataPropertyClass
    
    rowCount = Document.ActiveDataTableReference.RowCount
    rowsToInclude = IndexSet(rowCount,True)
    
    #Get a cursor to the two columns we want to use. cursor1 is for the key column and cursor2 is for the column selected by the user input
    
    cursor1 = DataValueCursor.Create[int](Document.ActiveDataTableReference.Columns["ProductID"])
    cursor2 = DataValueCursor.CreateFormatted(Document.ActiveDataTableReference.Columns[whichCol])
    
    #The following section will add a column to the database table using the name specified by the user. This assumes a column with this name does not already exist.
    
    sqlCommand = "ALTER TABLE Products ADD " + colName + " varchar(50);"
    dbsettings = DatabaseDataSourceSettings( "System.Data.SqlClient","Server=localhost;Database=myDB;UID=myuser;PWD=mypass",sqlCommand)
    ds = DatabaseDataSource(dbsettings)
    newDataTable = Document.Data.Tables.Add("temp",ds)
    Document.Data.Tables.Remove(newDataTable)
    
    #The following section will update the specified column in the database using the key column in the where clause
    sqlStr=""
    for  row in  Document.ActiveDataTableReference.GetRows(rowsToInclude,cursor1,cursor2):
       value1 = cursor1.CurrentValue
       value2 = cursor2.CurrentValue
       sqlStr = sqlStr +  "UPDATE Products SET " + colName + "='" + value2 + "' WHERE (ProductID=" + str(value1)  + ");"
    
    sqlCommand = "UPDATE Products "  + sqlStr + ";"
    dbsettings = DatabaseDataSourceSettings( "System.Data.SqlClient",
    "Server=localhost;Database=Northwind;UID=myuser;PWD=mypass",sqlStr)
    ds = DatabaseDataSource(dbsettings)
    newDataTable = Document.Data.Tables.Add("temp",ds)
    Document.Data.Tables.Remove(newDataTable)
    

    以上来自Tibco Spotfire 我已经使用它作为模板在spotfire 中使用SQL 服务器中的表创建票证系统。

    【讨论】:

    • 感谢您发布潜在的解决方案。如果我可以将它写入外部数据库也很好。在您的示例中,dbsettings 是您指定外部数据库的连接字符串和身份验证的地方吗?
    • 是的,没错。该示例连接到 SQL 数据库。 (示例是 SQL 示例中通常使用的 Northwind SQL 数据库)
    猜你喜欢
    • 2020-04-07
    • 1970-01-01
    • 1970-01-01
    • 2019-04-05
    • 2020-10-08
    • 1970-01-01
    • 1970-01-01
    • 2020-10-21
    • 2019-11-27
    相关资源
    最近更新 更多