Tip of the Week

Performing Data Entry and Analysis with TIBCO Spotfire

Spotfire provides a variety of mechanisms for accessing data, including local files, relational databases, web services, and everything in between.  One request which has come up more and more is the ability to perform data entry using Spotfire. This could be to store data in the underlying data source, it could be for a quick approach to analyze new data in the Web Player,  it could be for updating properties in the existing Data Table, or it could be to add rows or columns into a Data Table similar to how you would add them into an Excel file.

We will explore all these requirements in future tips. In this tip, we will focus on how to use a Spotfire file as a data source itself and load data into it one row at a time. In this scenario, we will want Spotfire to keep track of all our training course registrations.  Rather than entering them one at a time in Excel or in a database, we will enter them directly for input into Spotfire, appending them to the existing Data Table.


There are a variety of options for entering the data. You can use an HTML form which is outside of Spotfire to enter the data, and then use the Web Player APIs to load the data into Spotfire, or you can use a Text Area inside an existing Spotfire analysis file directly. In this tip, we will discuss the latter.


To start, we should load one row of our training registration data. This would be to initialize the Data Table and Spotfire Analysis file.  For this example, the format of the Data Table is shown below.


 
Then, we need to create the Text Area and Property Controls to allow the user to enter the data.  You can choose to simply use the out of the box features in a Text Area to create something similar to the image below:


 
Or, you can use a Script to create a custom layout for your Text Area, similar to what we discussed in earlier posts.  A sample of the information above, displayed in an HTML table, is shown below:

 

Once you create the Text Area and Property Controls that you would like to use, you will need to create a Script Control which will add the data to the currently loaded Data Table.  Assume we have each property control passed in as a parameter, and we call those parameters customer, type, date, costs, location, and company, the following script would add this information as a new row to our Data Table.


import clr
clr.AddReference("SpotfireTraining.ArrayDataSource, Version=1.0.0.0, Culture=neutral, PublicKeyToken=489d6add0b459834")
from SpotfireTraining.ArrayDataSource import ArrayDataSource
from System import Array,String,Object
from Spotfire.Dxp.Data import AddRowsSettings
from Spotfire.Dxp.Data import DataType

temp = Array[object ]((customer,type,str(date),str(costs),location,company))
ads =  ArrayDataSource(temp, Document.ActiveDataTableReference)
ars = AddRowsSettings(Document.ActiveDataTableReference, ads)
Document.ActiveDataTableReference.AddRows(ads,ars)

This example uses an ArrayDataSource, which is built using the full C# SDK. This allows us to pass information into Spotfire from an array.  If you did not have access to the SDK to create the Array Data Source, you can still use this functionality, but it requires you to use the built-in TextData Source. The code for this solution is shown below:

from System import Array,String,Object
from System.IO import Path, File, StreamWriter
from Spotfire.Dxp.Data import DataTableSaveSettings
from Spotfire.Dxp.Data.Import import TextFileDataSource
from Spotfire.Dxp.Data.Import import TextDataReaderSettings
from Spotfire.Dxp.Data import AddRowsSettings
from Spotfire.Dxp.Data import DataType
#Temp file for storing properties
tempFolder = Path.GetTempPath()
tempFilename = Path.GetTempFileName()


# generate data and write to file
f = open(tempFilename, 'w')
f.write(customer + '\t' + type + '\t' + str(date) + '\t' + str(costs) + '\t' + location + '\t' + company + '\n')
f.close()
# read file data and replace data table content
readerSet = TextDataReaderSettings()
readerSet.Separator = "\t"
readerSet.SetColumnName(0, "Customer")
readerSet.SetColumnName(1, "Type")
readerSet.SetColumnName(2, "Date")
readerSet.SetDataType(2,DataType.Date)
readerSet.SetColumnName(3, "Costs")
readerSet.SetDataType(3,DataType.Integer)
readerSet.SetColumnName(4, "Location")
readerSet.SetColumnName(5, "Company")
textDataSource = TextFileDataSource(tempFilename, readerSet)

ars = AddRowsSettings(Document.ActiveDataTableReference, textDataSource)
Document.ActiveDataTableReference.AddRows(textDataSource,ars)

Once completed, you know have a Spotfire Analysis file, which includes the data entry component for your solution , the analytic component, and also stores the data (the dxp file is the data source).  When the user enters the new information in the Property Controls and clicks on the Script Control button, the data is added to the existing Data Table as a new row and then persisted in the Spotfire Analysis file. All the existing pages and visualizations are automatically updated to analyze the latest data, including the row that was just added.

If you have a need to use this data in other applications, or you wish to store it outside the Spotfire Analysis file, you can add another step where you store the information into a database after you enter it in the Property Controls. Then the Data Table in Spotfire is updated using Spotfire’s data on demand technology. This will be discussed in an upcoming tip.

 

Comments

 

Rich Ellis said:

Whoa, you kind of glossed over the ability to create custom layouts in text areas with property controls!

In previous tips ("Creating Custom Reports with Script Controls"), you discussed how to cast a TextArea as an HTMLTextArea and load it with static HTML.  But in this tip, you seem to imply that you can use this technique to create complex layouts that include Property Controls. That is huge!

How do you reference property controls in HTML?

April 27, 2011 12:22 PM
 

richellis333 said:

Followup discussion in the forums:  spotfire.tibco.com/.../5197.aspx

April 27, 2011 3:16 PM
 

Tip of the Week said:

In last week’s tip we learned how to enter data via property controls inside TIBCO Spotfire and then

May 1, 2011 9:30 PM
 

msanchez37 said:

Thank you for this helpful post. I am very interested in taking the next step, referenced in the last paragraph of this tip, to store the data outside Spotfire (specifically in an Oracle database). You indicate that this would be discussed in an upcoming tip. Is this tip ready to be published? If not, could you provide me an outline of the solution steps?

Thanks again!

May 2, 2011 1:06 PM
 

J TIFFIN said:

I am creating data entry through text box and property controls and need more clarification on writing the script to add the data as a new row.

First -Did you create all your property controls as input fields? or is the column "type" using a drop down list?

second - where does this script reside and do i need developer to assist writing it? I have never written a script and need a basic starting point.

thanks for your assistance   jt

October 5, 2011 2:32 PM
 

J Tiffin said:

i was able to successfully add a data row using the action control. Now i have multiple pages where the user will type in the new data for these fields. (there are too many fields to have on one sheet)

My question is : if i put the action control on the last data entry page, will it pull all the property controls from the other pages in the dxp file?  if not how can i keep entering data on the same row that was inserted on the first page i created for data entry?

October 11, 2011 3:59 PM
 

beatsbydrdre110 said:

<a href="www.monsterbeatus.com/.../">Monster Beats</a>The only thing missing from Verlander’s pitching resume is a World Series title. He is 3-3 with a 5.57 ERA in eight career postseason starts, and went 2-1 in the playoffs this year as the Tigers reached the AL championship series before losing to Texas. <a href="www.monsterbeatus.com/.../">Cheap Beats by Dre</a>

<a href="www.monsterbeatus.com/">Cheap Dre Beats</a>Clayton Kershaw of the Los Angeles Dodgers is the favorite to win the NL Cy Young when the results are released Thursday. He won the NL pitching Triple Crown, leading with a 2.28 ERA and 248 strikeouts and tying for wins at 21.

<a href="www.monsterbeatus.com/">Dre Beats Headphones</a>The AL and NL Managers of the Year will be announced Wednesday.

<a href="www.monsterbeatus.com/">Monster Beat Headphones</a>Copyright 2011 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.

November 16, 2011 2:06 AM
 

uggkensington said:

http://www.uggkensingtons.org/

http://www.uggkensingtons.org/ugg-fox-fur-short-boots-5531-c-54.html | UGG Fox Fur Short Boots 5531

http://www.uggkensingtons.org/ugg-kensington-boots-5678-c-2.html | UGG Kensington Boots 5678

http://www.uggkensingtons.org/ugg-rainier-eskimo-boots-5189-c-85.html | UGG Rainier Eskimo Boots 5189

http://www.uggkensingtons.org/ugg-retro-cargo-boots-1895-c-3.html | UGG Retro Cargo Boots 1895

December 27, 2011 8:00 PM
 

uggskensingtonsale said:

www.uggskensingtonsale.org

www.uggskensingtonsale.orgugg-adirondack-boots-ii-c-6.html | UGG Adirondack Boots II

www.uggskensingtonsale.orgugg-adirondack-tall-boots-c-11.html | UGG Adirondack Tall Boots

www.uggskensingtonsale.orgugg-amberlee-boots-c-34.html | UGG Amberlee Boots

www.uggskensingtonsale.orgugg-annabelle-boots-c-35.html |

December 28, 2011 3:49 AM
 

kamal verma said:

years it has been waging an insurgency against the government, mainly through bombings. Hundreds have been killed in these attacks, mostly in the .

December 28, 2011 12:15 PM
 

kamal verma said:

This client-oriented and faith-rooted store aims at providing the best LV goods and services, such as top-class.<a href="www.directboatshipping.com/">yacht transport</a>

December 28, 2011 12:17 PM
 

uggretrocargosale said:

January 4, 2012 8:44 PM
 

Manohar Reddy said:

Online product data entry outsourcing to India can reduce your costs up to 60% and increase the productivity without any hassles. Our online product data entry includes database updation, online product entry, amazon entry, online stores data entry, catalog processing services.

January 13, 2012 4:01 AM
 

buy ritalin online said:

I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post. Hats off to you! The information that you have provided is very helpful.

March 19, 2012 5:48 PM

Leave a Comment

(required) 
(optional)
(required) 
Submit

Syndication

Tags

Other Spotfire Blogs

Spotfire's interactive information visualization and analytic solutions give users a remarkable experience for quickly and easily querying data and reporting results for superior business intelligence. From portfolio management and customer retention programs to key processes such as CRM, marketing, research, bioinformatics, yield and asset management and design for manufacturing, enterprises around the world rely on Spotfire's business analytics software to improve operational performance.

©Copyright 2000-2011 TIBCO Software Inc | Privacy Policy | Terms of Use I Blog I Contact Us I Content Center