Skip To Content

Use the scripting environment

Note:

The Insights scripting environment is available in Insights Enterprise and Insights Local.

The scripting environment is currently in beta, but it is publicly available to all Insights Enterprise users.

After a connection is made to a Jupyter Kernel Gateway, the scripting environment can be accessed and used to create and run scripts in Python and R. The scripting environment consists of an In[ ] cell, where scripts are loaded or written; an Out[ ] cell, where results are displayed; and a toolbar.

Open the scripting environment

To use the scripting environment, you must first set up a Jupyter Kernel Gateway and create a connection to the gateway. Once the gateway connection is created, use the following steps to open the scripting environment and start writing scripts:

  1. Open a workbook. Select data you want to add to your workbook, if necessary.
    Tip:

    You can also load data from within the scripting environment.

  2. Click the Scripting button Scripting on the workbook toolbar.

    The scripting environment opens.

    Note:

    If the New Jupyter Kernel Gateway connection window opens, it means you have not created a connection to the gateway. Enter the URL and web socket address to your gateway to create the connection. See Connect to a kernel gateway for more information.

  3. Use the Select Kernel menu to choose which kernel to use for scripting. Depending on the kernel gateway connection you are using, the options will be Python, R, or both.

    The scripting environment updates to include an In[ ] cell, as well as a toolbar.

The scripting environment is now ready to create, load, and run scripts.

Edit a script

Scripts can be edited from the In[ ] cells, even after the cell has been executed. To edit a script, click in the cell, make the edits, then run the cell. A new Out[ ] cell is created with the edited results.

Export a script

Scripts that are written in the scripting environment can be exported and saved as a .py script for Python, or a .R script for R. A script can be exported from the scripting environment using the Export button Export.

The following export options are available when you save a script:

  • Download Selected Cell—Saves only the script in the current In[ ] cell.
  • Download History—Saves the script from all In[ ] cells in the scripting environment as a Jupyter Notebook file (.ipynb).
  • Export History to Data Pane—Saves the script in the data pane of your workbook. All exported scripts are listed under a Scripts heading. A script in the dataset can be renamed using the Rename script button Rename script. A script can be opened in the scripting environment, removed from the data pane, or downloaded as a JSON using the Dataset options button Dataset options.

If the cell has already been saved to the data pane, Export History to Data Pane will be replaced with Update Script in Data Pane.

Exported scripts will be saved in the default download folder on your computer.

Load a script

Scripts can be created directly in the scripting environment by typing in the In[ ] cell. Existing scripts can also be loaded into the scripting environment using the following steps:

  1. Open the scripting environment, if necessary, and choose the correct kernel for the script you will be running.
  2. Click the Import file button Import File on the scripting environment toolbar.
  3. Browse to and open the script you want to run.

    The script is opened in the In[ ] cell.

  4. Click the Run button Run on the scripting environment toolbar.

The script runs and the results appear in the Out[ ] cell.

Scripts that have been exported to the data pane can also be loaded into the scripting environment. To load a script from the data pane, use the following steps:

  1. Expand the Scripts heading in the data pane.
  2. Click the Dataset options button Dataset options for the script you want to load.
  3. Click Open.

    The script is opened in the In[ ] cell.

Create an image card

Scripting results, such as charts, can be exported from an Out[ ] cell to create an image card on your Insights page. To export a cell, you must run your script using the Run button Run, highlight the Out[ ] cell, and then click the Create Card button Create Card to move the image from the most recent Out[ ] cell to an image card.

Note:

Image cards created from scripts are static and do not have the same interactive capabilities of map, chart, and table cards created in Insights.

Save your script to a model

The script in your scripting environment can be added to your model as an Insights scripting module using the Add To Model button Add To Model. The scripting module can be edited from the Analysis view Analysis view

Clear or close the scripting environment

The script, including all In[ ] and Out[ ] cells, can be cleared using the Restart button Restart. Clearing the scripting console cannot be undone.

The scripting environment is closed by clicking the close button Close or browsing to a different page within Insights. The script will not be saved once the scripting environment is closed. It is best practice to export your script before closing the scripting environment.

If you need to switch between the Insights page and the scripting environment, it is best practice to minimize the environment using the minimize button Minimize rather than closing it, so you will not lose your scripts.