How to read a CSV file from URL Using Spotfire

How to read a CSV file from URL Using Spotfire

book

Article ID: KB0070438

calendar_today

Updated On:

Products Versions
Spotfire Analyst 10.7 and higher

Description

Previously there have been suggestions to open a CSV file from URL via "Files and data flyout - Browse local file". This, however, downloads the CSV file from the Internet and saves it as a temp file in Windows. When you reload the data, it reloads the temp file from Windows instead of loading it from the Internet, so this could be inconvenient.
FileDialog

Issue/Introduction

Reading a CSV file from URL using the file dialog does not update the table when the CSV file is updated. Using a python data function to read the CSV file from URL will reread it every time Spotfire is opened or the data function is executed.

Resolution

One solution to this in Spotfire Analyst is to use a python data function (Introduced in Spotfire 10.7).
You then add a data function, running a python script that will download the file from the Internet. Every time the data function is refreshed, it will download the file again from the Internet.

How to register a data function:

Go to "Tools -> Register data functions... " to register your data function.
Name the data function, select type:"Python script", turn off caching and enter the following script, referencing your URL:
###################
import pandas as pd 
outTable = pd.read_csv("https://people.sc.fsu.edu/~jburkardt/data/csv/hw_25000.csv") 
###################
  RegisterDataFunction
Add the output parameter called 'outTable' under "Output Parameters".
  Register Data Function Ourput
By pressing "Run", you will be asked to declare input and output. In this case we only have one output: 'outTable'. Declare 'outTable' as creating a new table and call it myDataFromCSV.
Edit Parameters
When pressing OK, the data function will be executed and embedded in the dxp. When closing down the "Register data functions" window, you will be asked if you want to save it in the library as a separate function. Do so if you are going to reuse it, or just keep it embedded. By executing the data function, the data will be reloaded from the URL.
 

Additional Information