Use the scripting environment

Insights in ArcGIS Enterprise
Insights desktop
Note:

The Insights scripting environment is available in Insights in ArcGIS Enterprise and Insights desktop. The primary connection can be to either Insights in ArcGIS Enterprise or Insights in ArcGIS Online.

Jupyter Kernel Gateway connections can be disabled for an Insights in ArcGIS Enterprise organization during the installation process. Contact your administrator if the Jupyter Kernel Gateway connections are not available. For more information, see Install Insights in ArcGIS Enterprise.

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, complete the following steps to open the scripting environment and start writing scripts:

  1. Open a workbook, and add data to it if necessary.
    Tip:

    You can also load data from within the scripting environment.

  2. Click the Scripting button Scripting on the workbook toolbar.
  3. If a connection wasn't saved in the workbook previously, do one of the following:
    • In Insights desktop, if the New Jupyter Kernel Gateway connection window appears, it means you have not created a connection to the gateway. Provide the URL and web socket address to the gateway to create the connection. See Connect to a kernel gateway for more information.
    • In Insights in ArcGIS Enterprise, if the Kernel Gateway connection window appears, select an existing kernel gateway connection from the Environment name menu. You can also create a connection on the Add new tab. See Connect to a kernel gateway for more information.

    The scripting environment opens and a Scripts heading is added to the data pane.

  4. From the Select Kernel menu, choose the 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 use to create, load, and run scripts.

The script is automatically saved under the Scripts heading in the data pane with the name Insights Script. You can rename the script using the Rename script button Rename script.

The following options are also available for the script using the Dataset options button Dataset options:

  • Open—Load the script into an In[ ] cell.
  • Run—Run the script without opening the scripting environment.
  • Download—Download the script as a Jupyter Notebook file (.ipynb).
  • PublishPublish the script to create an Insights script item (available in Insights in ArcGIS Enterprise).
  • Remove—Remove the script from the data pane.

Edit a script

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

Export a script

You can export and save scripts that are written in the scripting environment as .py scripts for Python, or an .R script for R. To export a script from the scripting environment, select one or more cells, and click the Export button Export.

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

  • Download Selected Cell(s)—Save only the script in the selected In[ ] cells.
  • Download History—Save the script from all In[ ] cells in the scripting environment as a Jupyter Notebook file (.ipynb).

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

Load a script

You can create scripts directly in the scripting environment by typing in the In[ ] cell. To load existing scripts into the scripting environment, complete 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 are saved in the data pane can also be loaded into the scripting environment. To load a script from the data pane, complete 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 the script using the Run button Run, highlight the Out[ ] cell, and 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 the script to a model

You can add the script from the scripting environment to a model as an Insights script using the Add To Model button Add To Model. The Insights script can be edited from the Analysis view Analysis view. For more information about updating a model in Insights, see Rerun your analysis.

Clear or close the scripting environment

To clear the scripting environment, including all In[ ] and Out[ ] cells, click the Restart button Restart. Clearing the scripting environment cannot be undone.

To close the scripting environment, click the close button Close or browse to a different page in Insights.

To switch between the Insights page and the scripting environment, minimize the environment using the minimize button Minimize rather than closing it, so you will not lose your scripts.