Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Apr 3, 2025. It is now read-only.

(Deprecated: This repository is no longer maintained.) A guide and samples for working with the ArcGIS Insights scripting environment.

License

NotificationsYou must be signed in to change notification settings

Esri/insights-scripting-guide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This repository has reached the end of its journey. It is now officially deprecated and will no longer be maintained. Thank you to all the users. Farewell, and onward to new endeavors. Read the announcementhere

Insights Scripting Guide

This guide offers a reference for creating custom features in ArcGIS Insights using Python and R. It is the definitive guide for Insights scripting topics and a resource for implementing Jupyter's Kernel Gateway.

Check out the wikihere

Prerequisites

  • ArcGIS Insights (version 2020.x or above). Referreadme for details on versions.
  • Anaconda (with Python version 3.7 or above)
  • See needed Python and Rdependencies

Note: Scripting is not supported in Insights running in ArcGIS Online. DownloadInsights Desktop for this instead, which supports ArcGIS Online connections, ArcGIS Enterprise connections, database and scripting features.

Note: Plots created with pandas i.e., pandas.DataFrame.plot() are not displayed in the cards when added to a script model.

You can access an archived version of this documentationhere.

Setup Kernel Gateway

Insights supports connections to Jupyter's Kernel Gateway, which is an open source web server distributed throughconda-forge and other repository channels. To setup a Kernel Gateway, with the required dependencies follow the deployment instructions below.

Check outDeployment Patterns for system planning recommendations.

Deploy with Anaconda

Note: If you have already created the conda environment, skip to this sectionhere

  1. InstallAnaconda

  2. Create a folder namedgateway

  3. Copyselfsign.py intogateway folder

  4. Copy the.yml file into thegateway folder.

  5. OpenAnaconda's command prompt and CD into thegateway folder

  6. If you are using2023.1, 2023.2, 2023.3 or above versions of the ArcGIS Insights, run the following commands:

    conda env create -f insights-latest.ymlconda activate insights-latestpython selfsign.py

Note: If the process of creating a conda environment is taking too long, follow these instructions to create the environmenthere

  1. If you are using any of the versions2021.2, 2021.3, 2022.1, 2022.2, or 2022.3 of the ArcGIS Insights, run the following commands:

    conda env create -f insights-2022.ymlconda activate insights-2022python selfsign.py
  2. If you are using any of the versions2020.2, 2020.3 or 2021.1 of the ArcGIS Insights, run the following commands:

    conda env create -f insights-base.ymlconda activate insights-basepython selfsign.py
  3. Start the Kernel Gateway:

  • If you are usingInsights in ArcGIS Enterprise, run the following command:

    jupyter kernelgateway --KernelGatewayApp.ip=0.0.0.0 --KernelGatewayApp.port=9999 --KernelGatewayApp.allow_origin='*' --KernelGatewayApp.allow_credentials='*' --KernelGatewayApp.allow_headers='*' --KernelGatewayApp.allow_methods='*' --JupyterWebsocketPersonality.list_kernels=True --certfile=./server.crt --keyfile=./server.key --KernelGatewayApp.kernel_manager_class=notebook.services.kernels.kernelmanager.AsyncMappingKernelManager
  • If you are usingInsights Desktop, run the following command:

    jupyter kernelgateway --KernelGatewayApp.ip=0.0.0.0 --KernelGatewayApp.port=9999 --KernelGatewayApp.allow_origin='*' --KernelGatewayApp.allow_credentials='*' --KernelGatewayApp.allow_headers='*' --KernelGatewayApp.allow_methods='*' --JupyterWebsocketPersonality.list_kernels=True --KernelGatewayApp.kernel_manager_class=notebook.services.kernels.kernelmanager.AsyncMappingKernelManager
  1. Open the kernel gateway url in the browser before using it to connect in the Insights web application. For example: If you are using Insights in Chrome, open the gateway url in a new tab in Chrome, and bypass the security exceptions. Similarly, if you are using Insights in Safari or Firefox, open the gateway url and bypass the security exceptions. For more detailed instructions on bypassing security exceptions, referwiki

  2. When you open the gateway url (ex:https://pickle.esri.com:9999), you will see a JSON response as{"reason": "Not Found", "message": ""}. This is a valid message and it indicates that our kernel is up and running and it is ready to use within Insights. This message is just a default swagger-api's response. If you are interested in more detailed response regarding the kernel, you can navigate toapi/kernelspecs page (ex:https://pickle.esri.com:9999/api/kernelspecs)

  3. Do not close the Anaconda prompt or the terminal window after starting the kernel gateway. Just minimize it. Closing the window will kill the kernel gateway.

  4. Optional: Stop Kernel Gateway by pressingControl-C in the running window or close the window.

Note: If you would like to access your data (.csv,.xls, etc.,) in the scripting environment, create adata folder withingateway folder and put your files in it. Then, activate your conda environment after CD'ng into thedata folder and run the appropriate gateway command to start the gateway.

Alternative method to create a conda environment

In some cases, creating a conda environment using a yml file takes a long time, and the process might get stuck as conda is trying to solve the environment by resolving the conflicts between some of the dependencies. Instead of waiting for the process to resolve, we can install the packages one by one. Follow the instructions below to quickly create your environment.

  1. OpenAnaconda's command prompt and CD into thegateway folder.
  2. Creating a new environment and installing dependencies:
  • If you are using2023.1, 2023.2, 2023.3 or above versions of the ArcGIS Insights, run the following commands:

    # Creates a new environment named `insights-latest` with Python 3.9.14 installed.conda create -n insights-latest -c conda-forge python=3.9.14
    # Activates the insights-latest environment.conda activate insights-latest
    # Installs the packages from conda-forge channel.conda install -c conda-forge jupyter_kernel_gateway=2.5.1 pandas=1.5.1 shapely=1.8.5 msgpack-python=1.0.4 matplotlibconda install -c conda-forge geopandas=0.11.1conda install -c conda-forge pyspark=3.3.1# You can skip the following if you don't need R kernel.conda install -c conda-forge r-itertoolsconda install -c conda-forge r-essentials
    # Creates certificates in the gateway folder.python selfsign.py
  • If you are using any of the versions2021.2, 2021.3, 2022.1, 2022.2, or 2022.3 of the ArcGIS Insights, run the following commands:

    # Creates a new environment named `insights-2022` with Python 3.7.12 installed.conda create -n insights-2022 -c conda-forge python=3.7.12
    # Activates the insights-2022 environment.conda activate insights-2022
    # Installs the packages from conda-forge channel.conda install -c conda-forge jupyter_kernel_gateway=2.5.1 pandas=1.5.1 shapely=1.8.5 msgpack-python=1.0.4 matplotlibconda install -c conda-forge geopandasconda install -c conda-forge pyspark=3.1.0# You can skip the following if you don't need R kernel.conda install -c conda-forge r-itertoolsconda install -c conda-forge r-essentials
    # Creates certificates in the gateway folder.python selfsign.py
  1. Start the kernel gateway:
  • If you are usingInsights in ArcGIS Enterprise, run the following command:

    jupyter kernelgateway --KernelGatewayApp.ip=0.0.0.0 --KernelGatewayApp.port=9999 --KernelGatewayApp.allow_origin='*' --KernelGatewayApp.allow_credentials='*' --KernelGatewayApp.allow_headers='*' --KernelGatewayApp.allow_methods='*' --JupyterWebsocketPersonality.list_kernels=True --certfile=./server.crt --keyfile=./server.key--KernelGatewayApp.kernel_manager_class=notebook.services.kernels.kernelmanager.AsyncMappingKernelManager
  • If you are usingInsights Desktop, run the following command:

    jupyter kernelgateway --KernelGatewayApp.ip=0.0.0.0 --KernelGatewayApp.port=9999 --KernelGatewayApp.allow_origin='*' --KernelGatewayApp.allow_credentials='*' --KernelGatewayApp.allow_headers='*' --KernelGatewayApp.allow_methods='*' --JupyterWebsocketPersonality.list_kernels=True --KernelGatewayApp.kernel_manager_class=notebook.services.kernels.kernelmanager.AsyncMappingKernelManager

Starting the kernel gateway

Note: If you haven't created a conda environment. Refer to the instructionshere

  1. OpenAnaconda's command prompt and CD into thegateway folder.
  2. Activate the conda environment:
  • If you are using2023.1, 2023.2, 2023.3 or above versions of the ArcGIS Insights, run the following command:

    conda activate insights-latest
  • If you are using any of the versions2021.2, 2021.3, 2022.1, 2022.2, or 2022.3 of the ArcGIS Insights, run the following command:

    conda activate insights-2022
  • If you are using any of the versions2020.2, 2020.3 or 2021.1 of the ArcGIS Insights, run the following command:

    conda activate insights-base
  1. Start the Kernel Gateway:
  • If you are usingInsights in ArcGIS Enterprise, run the following command:

    jupyter kernelgateway --KernelGatewayApp.ip=0.0.0.0 --KernelGatewayApp.port=9999 --KernelGatewayApp.allow_origin='*' --KernelGatewayApp.allow_credentials='*' --KernelGatewayApp.allow_headers='*' --KernelGatewayApp.allow_methods='*' --JupyterWebsocketPersonality.list_kernels=True --certfile=./server.crt --keyfile=./server.key--KernelGatewayApp.kernel_manager_class=notebook.services.kernels.kernelmanager.AsyncMappingKernelManager
  • If you are usingInsights Desktop, run the following command:

    jupyter kernelgateway --KernelGatewayApp.ip=0.0.0.0 --KernelGatewayApp.port=9999 --KernelGatewayApp.allow_origin='*' --KernelGatewayApp.allow_credentials='*' --KernelGatewayApp.allow_headers='*' --KernelGatewayApp.allow_methods='*' --JupyterWebsocketPersonality.list_kernels=True --KernelGatewayApp.kernel_manager_class=notebook.services.kernels.kernelmanager.AsyncMappingKernelManager

Create a connection

To create a connection to your Kernel Gateway follow these steps:

  1. Open Insights
  2. Create a new workbook
  3. Click theScripting iconOpen console
  4. Complete Kernel Gateway connection form

Note: Connections must reference the Kernel Gateway root URL. For tips on what connections may look like seeConnection examples.

Connection examples

Urls may be HTTP or HTTPS. Hosts can be referenced in numerous ways, IP address, localhost, FQDN etc. You can use any available inbound port number that is not already in use. If using 443, a connection will not require the port number. Here are some examples.Yes means connection schema is supported. No, means that URL connection will likely fail (not work).

Connection URLInsights in EnterpriseInsights Desktop
http://localhost:9999noyes
https://localhost:9999nono
http://pickle:9999noyes
https://pickle:9999nono
http://12.120.95.153:9999noyes
https://12.120.95.153:9999yesno
http://pickle.esri.com:9999noyes
https://pickle.esri.com:9999yesno1

1 Insights Desktop can make connections to HTTPS Kernel Gateway endpoints, if the Kernel Gateway uses a domain or a certificate authority certificate.

2 If using port 443, the connection url will look like thishttps://pickle.esri.com. Herepickle is the machine name.

Note: In Chrome, when trying to access the gateway url, it will give you a "Your connection is not private" warning. Click somewhere on the page and then blindly type the wordthisisunsafe. This will instantly bypass the warning.

General Features

Python and R scripting features are distributed across the app. Shared scripts are accessed from theAdd dialog. Script modules and module options are accessed via theData Pane. Lastly, theConsole itself has many script features. Refer to this table for an overview of tools and capabilities.

IconTool NameDescription
Open consoleOpen consoleOpens the Python and R scripting console or Kernel Gateway connection dialog. If no Kernel Gateway connection exists within the page, this is when the connection dialog openes.
Create moduleCreate moduleCreates a script from selected cells then adds a module to the data pane.
Create cardCreate cardTakes the active cell and creates a card.
Delete cellDelete cellDeletes the active cell.
Export scriptExport scriptEnables saving of cell (or cells) to common formats like Python, R, or Jupyter Notebook files.
Import fileImport fileEnables importing of scripts into the console from common files like Python, R or Jupyter Notebook files.
Insert cellInsert cellInserts a new scripting cell.
Restart kernelRestart kernelRestarts the execution kernel within the Kernel Gateway. Restarting stops running scripts and clears the namespace and any data held in memory.
RunRunRuns script in active cell.
Run allRun allRuns all scripts in active cell.
Switch connectionSwitch connectionEnables connection changing from one Kernel Gateway to another.

Shortcuts

The console enables keyboard shortcuts to perform routine tasks quickly.

ShortcutDescription
Ctrl + BCreate comments for selected code.
Shift + EnterExecutes code in current cell.
Ctrl + Alt + BAdds%insights_return(<data frame object>) magic command to cell

Magic commands

The console supports the following magic command. This magic command must be placed in it's own cell.

Magic commandDescription
%insights_return(<data frame object>)Converts Python or R data frames into Insights datasets. When%insights_return(df) is run it will generate an Insights dataset from thedf object. Data will be persisted in the workbook (when the workbook is saved) and will appear in the data pane after execution.

Deployment Patterns

There are various configurations to choose from when planning a Jupyter Kernel Gateway with Insights. It should be noted that some configurations may have tactical advantages over others. Additionally, each configuration will offer different end user experiences and varying degrees of effort regarding setup and maintenance.

These conceptual diagrams were designed to help organizations visualize different kinds of Jupyter Kernel Gateway configurations next to different kinds of Insights deployments.

Insights Desktop and Kernel Gateway

Insights Desktop and Kernel Gateway

  • This configuration entails low newtworking and firewall considerations
  • Data files may live on personal computer or file server

Insights in ArcGIS Enterprise and Kernel Gateway

Dedicated

Dedicated Kernel Gateway

  • This configuration entails moderate networking and firewall considerations and skills
  • Data files should live on file server or Kernel Gateway machine

Co-Located

Co-Located Kernel Gateway

  • This configuration entails moderate networking and firewall considerations and skills
  • Data files should live on file server or Kernel Gateway machine

Client Kernel Gateway System Design

Client Kernel Gateway

  • This configuration entails moderate networking and firewall considerations and skills
  • Data files may live on personal computer or file server

Cloud Kernel Gateway

  • Data files may need to be accessible from the cloud
  • This configuration entails advanced networking and firewall skills and considerations

Cloud Kernel Gateway

What is ArcGIS Insights?

Part of the Esri Geospatial Cloud, ArcGIS Insights is data analytics made for advanced location intelligence. Using Insights you can ask questions you did not know to ask, analyze data completely, and tell powerful data stories. Connect to your data directly, then use maps, charts, tables and reuseable models and scripts to perform basic to complex analyses that scale based on skill level and business need.

FAQs and Troubleshooting

How do I install additional Python libraries using the console that are not in my Kernel Gateway?

You can do this by putting an explanation point in front of apip install command. Like,

!pip install BeautifulSoup4

If all goes well (after running the command), download activity will apear in the output cell. When the command finishes, you can then import your library and run scripts like normal.

frombs4importBeautifulSoupsoup=BeautifulSoup("<p>Hello Insights!</p>")print(soup.prettify())

Insights is running in the web browser and when making a Kernel Gateway connection it says "Not able to add this connection. Try with a different URL or web socket or check if your gateway is running."

If you've followed the guide (and ran the selfsign.py file), you have created a self signed SSL certificate. It may be possible that Insights cannot make a connection because the web browser itself does not trust the certificate. To work around this problem open the kernel gateway URL in the web browser and accept the browser warning. Then try connecting again.

WebSocket connection to gateway url failed: Error during WebSocket handshake: Incorrect 'Sec-WebSocket-Accept' header value?

This error can occur on a windows machine and when this happens, you will see an indefinite progress spinner in the scripting environment. This error can be found in the browser console and can be resolved by installing Websockets on IIS. Go to the Server Manager > Manage > Add Roles and Features > Server Roles > Web Server > Application Development > WebSocket Protocol. Make sure this is checked. Refer:Link

My Kernel Gateway is on a different machine and I am having trouble making a connection using Insights?

A fundamental way to troubleshoot this problem is confirm that all needed computers can talk to each other. If you are running Insights in Enterprise this means each ArcGIS Server machine, plus your Kernel Gateway and personal computer must all be able to communicate with each other. Insights Desktop entails less troubleshooting. For Insights Desktop deployments, only the Kernel Gateway and your personal computer need to talk to each other.

Try getting the IP address of:

  • Your personal computer machine
  • Your kernel gateway machine
  • Your ArcGIS Server machine(s)

and then from each machine run theping command to see if ping messages are received.

Tip: On windows, runipconfig and reference the Iv4 address to get the IP address. On mac, runipconfig getifaddr en0 and note the address.

Seeing any other setup or connection issues?

If you encounter any issue which you are unable to troubleshoot, open your developer tools and see if there are any error messages in the console and create an issue on the repo with the error message. We will get back to you as soon as possible with a possible solution.

Tip: To open Developer tools of the web browsers, useShift + Ctrl + I on Windows andOption + Cmd + I on Mac.

Get Insights Desktop

Download Insights Desktop

Licensing

Copyright 2020 Esri

Licensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.

A copy of the license is available in the repository'slicense.txt file.

About

(Deprecated: This repository is no longer maintained.) A guide and samples for working with the ArcGIS Insights scripting environment.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors4

  •  
  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp