Kinduct has created a script that allows you to import data into your Kinduct site using R-Studio. This integration allows for secure transfer of data from user environments into the platform.
Additional configuration to your platform is not required to use the script as the current Kinduct API is used. However, before you can use the script you will need:
- Kinduct API credentials: Contact your CSM to obtain your site-specific “CLIENT ID” key and “CLIENT SECRET” key.
- Installation of R (version 3.0.0 or greater) and/or R-Studio (version 0.99.902 or greater) on your computer with the ability to install packages in the R environment.
- Internet access.
NOTE: Advanced knowledge of R-Studio is not required to run the script; however, some basic tasks in R-Studio must be completed to implement the script.
Setting Up the Script
There are a few tasks that need to be completed before you can use the script to import data into your Kinduct site. The following tasks must be performed in R-Studio:
- Install required packages.
- Download and add the Kinduct-provided script to your environment.
- Configure the script with your site-specific information.
Installing Requires Packages
If you are using R-Studio for the first time, you need to ensure that the following packages are installed for the script to run:
To install the packages:
- Open R-Studio.
- Click Packages tab.
- Click Install.
The Install Packages dialog displays.
- Type the name in Packages field to search (e.g. jsonlite).
The package name should auto-complete as you start to type, select from the list and click Install.
NOTE: The installation of these packages only needs to be done once. The script will load them each time it is run.
Adding Script to R-Studio
The import script is provided to you from your CSM in an .rtf file format. Once the file is downloaded to your computer:
- Open a blank R-Studio screen.
- Copy the contents of the .rtf script file and paste to R-Studio.
- Save the script in R-Studio. The script can now be configured and customized in R-Studio.
NOTE: It is recommended to save the copy of the script in .rtf format in case you need to revert back to the default script at any time.
Configuring the Script with Client-Specific Credentials
The provided script needs to be configured with API credentials that are site-specific. You must obtain your Client Secret key, Client ID key, and Client Name from your CSM if you want to use the script.
To configure the script:
- Open the script in R-Studio.
- Locate the # QUERY DATA parameters in the script.
- Enter the client_secret key, client_id key, and clientname that were provided to you.
Once the proper credentials are setup, you are ready to customize the script according to what data you want to import into the platform and the source format of the data to import (method for importing).
The provided import script is configured with function code to import from a data table in R or a csv file from your computer. You must customize the code in the script according to your source data.
Importing from a Data Table
The data table code is provided for situations where data has been exported from your Kinduct site into a data table, new data has been created, now all of the data needs to be imported back into your Kinduct site.
Required Data Format
You must ensure that the data that you want to import is in the correct format in the data table and the script, specifying the columns as shown below:
The following four columns are required, exactly as written in lowercase and must be the first four columns of your data table and script, in this order:
- type: name of metric.
- segment: if used.
- date: date that the data is for. The format must be yyyy-mm-dd.
- name: player or person that data is associated with. The format must be FirstName LastName (with space in between).
Additional columns can be defined after these four required columns. You can add whatever columns you want, according to the data that you are importing. The naming of these metrics is flexible, as long as they come after the first four data columns.
Data table based on the script above:
NOTE: The data_to_kinduct function is the function that actually performs the import. This function does not need to be modified and should not be modified.
Running the Script
The script contains function code for two different scenarios, therefore the script can’t be run from top to bottom. Highlight the desired sections and then run the script with any of the methods described in RUNNING THE SCRIPT.
While the script is running, a red icon displays in the console.
Once the script is complete, the red icon disappears and the following text shows in the console:
$ ‘Import Status’
This status means that the script worked. The data has been successfully imported into your Kinduct site with the correct credentials and the players have been properly linked in the site. Any other number indicates that the import was unsuccessful.
Uploading a CSV File
The code for uploading a csv file is provided for situations where you have a csv file on your local computer containing data that you want to be in your Kinduct site. First, this data must be imported into R-Studio and then from R-Studio, imported into your Kinduct site. The script performs these steps for you.
The CSV script includes functions for defining the working directory (setwd) and filename to read data from. In the example below, “import test” is set as the working directory for the location of the source csv file on the local computer and “import_data.csv” is the filename to read data from.
These parameters must be customized for your environment.
When this script is run, data from the defined csv file is imported into R-Studio into a data table format, then the newly created data table in R-Studio is imported into Kinduct.
Running the Script
Once the script is configured and/or customized, it is ready to run (also called “sourcing” the script).
To run the script from Mac OS:
- Using R, do one of the following:
- Click anywhere in your script and press Command + E.
- Click Edit ⟶ Source Document.
- Click the “Source” button.
- Press Command + Shift + S.
- Click Code ⟶ Source.
To run the script from Windows:
- Using R :
- Choose Edit ⟶ Run all
- Using R-Studio, do one of the following:
- Click anywhere in the source window and press Ctrl + Shift + S / Ctrl + Shift + Enter.
- Click the “Source” button.
Video walkthrough tutorial of the import code: