Jump to content
  • How to Deploy Custom Python Modules for Use in Spotfire®


    This article show how to Deploy Custom Python Modules for Use in Spotfire®

    Introduction

    The purpose of this article is to outline the steps necessary to package custom python modules, py files and deploy them to Spotfire Server for usage by Spotfire Clients (Analyst, Web Player) users

    Prerequisites

    • You must have administration access to Spotfire Server
    • You myst have Spotfire Developer License enabled

    Step 1: Create or gather the Custom Python Module file

    In this example, we create a custom python module file.

    • Create new folder where you will place your custom python module file.

    • Launch a text editor such as Notepad. Add the following function definition:

       def hello(string):
           return "Hello %s!" % (string,)
       
    • Save the file as mymodule.py into the new folder created in the previous step.

    Step 2: Create a package file (*.spk)

    This steps requires to use the Spotfire SDK. This is a separate software that can be obtained if you have a Spotfire Developer License. If this is the first time that you use the Spotfire SDK, see the referenced links below for installation instructions.

    • Launch the SDK Package Builder

    • Click the 'Add' button to add a new project

    • On the next window, leave selected the option 'Add project: From folder:' > Click Browse and select your python files folder (this is the directory where you have kept all the files needed for this implementation)

    • Un-check the button for 'Source code folder'

      packagebuilder-addfile_0.png.e5c78bead2bd515da13bb8ea0f43c24b.png
    • Click Next

    • Leave the default option for creating the module.xml file

      packagebuilder-module.png.2a12ba6a6ff088337d432963c608ea59.png
    • Click Next

    • Select your PythonModule file to include within the package

    • Make sure that you are giving the python module file (*.py file) a Public resource name with the same name.
    packagebuilder-publicresource.png.2b784c9db56c640bb26c4f385ec6dbf4.png
    • Click Next

    • Change the intended client to "TIBCO Spotfire Any client" to use the custom python module on all TIBCO Spotfire clients and provide other information such as name and version number

      packagebuilder-name_0.png.a3eaab9ef114600ac4597ed96032f868.png
    • Click Finish

    • Click the Validate and Save button

      validateandsave.png.52c81ad8a33621c799bc3271a85eca4f.png
    • Right click on the module and build an SPK file

      build.png.bcb472f07e4d6f197946d5df78761199.png

    Step 3: Deploy the Package File onto Spotfire Server

    • Launch your browser and navigate to the TIBCO Spotfire Server Administration Console. http://<host>:<port>/spotfire/#/deploymentsPackages
    • Select a Deployment Area and click Add packages
    • Browse and select the package file(.spk) file that you created
    • Click Upload to add the package to the Deployment Area
    • Click Validate area
    • Then, click Save area

    addpackage.thumb.png.8b2bef3f3c43a4594358e605ddd96772.png

    Step 4: Use your Custom Python Module in TIBCO Spotfire Analyst

    • Start Spotfire Analyst client and connect to the Spotfire Server to install the package
    • Create a script importing mymodule and calling 'hello' function as below:
     from Spotfire.Dxp.Framework.ApplicationModel import NotificationService
     import sys
     sys.path.append(ModulesService.GetResourceDirectoryPath("mymodule.py"))
     from mymodule import hello
     
     # Call Hello function
     x= hello("world");
     print x;
     
     # Notification service
     notify = Application.GetService[NotificationService]();
     notify.AddInformationNotification("Custom Python Module","Hello Function",str(x));
     

    script_1.thumb.png.077aeeb3ce36d01dffac66c5293539b7.png

    Results

    result_0.png.ae8a2bb5733d5b17c8102ab3cfca4587.png

     

    References

    mps-interface-tibco-spotfire-software.pdf

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...