Sometimes in Spotfire I want to generate a quick/small table that contains user input rather than storing it in a bunch of document properties. There’s a nice, quick way to do this using TERR.
I just made a simple data function that takes two parameters:
- Colnames – String of column names separated by commas
- DataText – A comma delimited (csv format) data to feed the table
The data function returns a DataTable called “Result”.
In the TERR code, we concatenate the column names and data and read it in as a csv file directly to a R data frame. Spotfire naturally translates this to a data table when it is returned.
You could add some error catching to protect against bad inputs, but here is simple set of code:
lines = paste(Colnames,"\n", DataText) conn = textConnection(lines) Result = read.csv(conn) close(conn)
All we have to do is run this whenever the inputs change (basically whenever we change the DataText input) and it automatically updates the resulting table.
To populate the table, you could either expose a text area for direct input by the user or you could generate it in IronPython whenever a document property changes. For instance, you could concatenate several document properties into a result table, which would then be used to feed a visualization or be used in a subsequent data function.
You could also create a table through IronPython, but this is a nice way to have it run asynchronously and smoothly. Plus, you could do some extra magic in the TERR function if that was needed in the workflow.
If you want to download this example, we have it hosted on Exchange.ai