# Creating an SPK to put a CRAN Package on Spotfire Server

By running a few lines of TERR code, you can create a Spotfire SPK that you can deploy to Spotfire Server for use by the Spotfire web clients.

## About this task

You can create an SPK containing packages, you can add a package to an existing SPK, or you can remove a package from an SPK. This topic demonstrates creating an SPK containing two packages by downloading the packages, and then creating the Debian Control File (DCF) that specifies the package contents.

Perform this task from the TERR console.

You must use the same version of TERR that is running in the TERR Service on the node manager. This version of TERR must be a supported version, as listed in the System Requirements.

Note: On Windows, start the TERR console available from the Tools menu in Spotfire Analyst.

## Before you begin

- Review the SPK information in this Help.
- You must have access to the TERR console.
- You must have access to the Spotfire Server deployment area.
- You must have access to an internet connection that allows you to download packages from CRAN.
- You must build a package for the operating system on which your Spotfire Server node manager is installed.

## Procedure

1. From the TERR console, install the packages you want to include in the Spotfire SPK.
   This example shows installing two packages. The function that builds the SPK includes all Includes and Depends packages in the SPK.

       install.packages(c("dplyr","zoo"))

   Note: If you are running Windows, you can install the packages you want in Spotfire Analyst from the TERR Tools Package Management dialog box.
2. In the TERR console, generate a list file.
   In this example, we create the Debian Control File (DCF), which is a list file that contains the two sample packages.

       writeLines("Packages: dplyr,zoo", "ServerSPK.dcf")

   The file ServerSPK.dcf contains one line: `"Packages: plyr,zoo"`. (Make a note of the file location.)
3. Load the library that contains the functions to create the SPK for Spotfire Server.

       library(SpotfireSPK)

4. In the TERR console, call the function that creates the SPK, and pass in the name of the DCF you created, and then add the packages to an SPK named ServerSPK.spk.

       buildServerSPK("ServerSPK.dcf", "ServerSPK.spk")

   The Spotfire package file is created, and the file ServerSPK.dcf now contains the information similar to the following:

       Packages: dplyr,zoo
       Built: TERR service <ver>; 2023-02-27 17:17:48 PST
       BuiltFile: ServerSPK.spk
       BuiltName: TERR™ - Server Edition (a/k/a TERR™ service) Packages for Spotfire Server
               Windows 2116732a
       BuiltId: 2116732a-306b-48e1-9a66-da12286a44ce
       BuiltVersion: 1.0.0.0
       BuiltPackages: R6 (>=2.4.1),assertthat (>=0.2.1),cli (>=2.1.0),crayon
               (>=1.3.4),digest (>=0.6.25),dplyr (>=1.0.2),ellipsis
               (>=0.3.1),fansi (>=0.4.1),generics (>=0.0.2),glue
               (>=1.4.2),lattice (>=0.20-41),lifecycle (>=0.2.0),magrittr
               (>=1.5),pillar (>=1.4.6),pkgconfig (>=2.0.3),purrr
               (>=0.3.4),rlang (>=0.4.8),tibble (>=3.0.4),tidyselect
               (>=1.1.0),utf8 (>=1.1.4),vctrs (>=0.3.4),zoo (>=1.8-8)

   Note: The `BuiltVersion` is always `1.0.0.0` when you create the DCF using TERR, and then to create an SPK, unless you specify a different version in the function call. See Spotfire SPK versioning for more information.

   The SPK is ready to be placed in the Spotfire Server deployment area. Make a note of its location.

5. Open a browser window and log in to Spotfire Server as the administrator.
6. Click Deployments & Packages.
7. Under Software Packages, click Add Packages.
   The Add packages dialog box is displayed.
8. Browse to the location of the new SPK file, and then select it and click Open.
9. Click Upload.
10. Click Save area to save the deployment area.

## Results

The packages are added to the Spotfire Server node manager where the TERR service is deployed. They are ready to use in a visualization published for Spotfire web client users.

If you already installed the TERR service to your node manager, you must upgrade the service for the newly-installed packages to be deployed.