Jump to content

I would like to replace data(Replacedata()) using ironPython script from Library Folder in Spotfire Server. but it fails. Please let me know how to avoid it.


Morio Saeki 3
Go to solution Solved by Gaia Paolini,

Recommended Posts

ReplaceData() from Library folder in Spotfire server. --> Fail

ReplaceData() from local folder. --> Success 

I use Spotfire Analyst Version 10.10.3 LTS HF-019 build version:10.10.2.33.

​​

[Replace Data file]

: CSV file (ReplaceData() succes from local folder)​

: The CSV file was saved in the Library folder using Sopotfire'Analyst's export function.

[ReplaceData() Result in my environment]

- Replace using Data canvas from Library folder​ : Success

- ReplaceData() using ironPython script from local folder : Success

- Replacedata() using ironPython script from Library folder : fail

csv filename = template1: cannot be opened. It may be damaged or in an unknown format.

csv filename = template1_exported.csv:  name 'filePath' is not defined

[Test Script] - I only changed only filePath to match the test environment.

----------------------------------------------------------------------------------------------------------

import clr

import Spotfire.Dxp.Data.DataTable

from Spotfire.Dxp.Data import *

clr.AddReference("System.Windows.Forms")

from System.Windows.Forms import OpenFileDialog

from Spotfire.Dxp.Data import *

myDataManager = Document.Data

filePath = "/User/saeki/template1"  #cannot be opened. It may be damaged or in an unknown format.

ds=myDataManager.CreateFileDataSource(filePath)

table.ReplaceData(ds)

----------------------------------------------------------------------------------------------------------

Link to comment
Share on other sites

  • Solution

Your csv data would be stored in the library as a sbdf. The way to retrieve something from the library is quite different.

This code should work. Replace the path to your library path (excluding the word 'Library') ending with '/' and your file name in filePath accordingly.

The variable table is an input parameter of type DataTable.

  1. from Spotfire.Dxp.Data import *
    from Spotfire.Dxp.Framework.Library import LibraryManager, LibraryItemType
    from Spotfire.Dxp.Data.Import import SbdfLibraryDataSource
     
    libraryPath ='/yourpath/'
    filePath = 'yourfile'
     
    manager = Application.GetService[LibraryManager]()
     
    (found, item) = manager.TryGetItem(libraryPath+filePath,LibraryItemType.SbdfDataFile)
     
    print(found)
    if found:
    ds = SbdfLibraryDataSource(item)
    table.ReplaceData(ds)

     

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...