top of page

Combining Python Dictionaries with ArcGIS Notebook Custom Web Tools

  • Writer: Haley Brueckman
    Haley Brueckman
  • Jun 3
  • 3 min read

As of June 2024, ArcGIS Online supports creating custom web tools directly from ArcGIS Notebooks. This integration allows users to develop Python scripts and publish them as custom tools that can seamlessly run within ArcGIS Web Maps and other ArcGIS web applications like Experience Builder. By leveraging Python within ArcGIS Notebooks, users can create interactive tools that simplify complex workflows without exposing the underlying code.

One powerful use case is combining input parameters with Python dictionaries to provide users with dynamic, selectable options. In this blog, we’ll explore how to set up a custom web tool in ArcGIS Online that uses a dictionary to generate a choice list for the user.


Setting Up an ArcGIS Notebook

To create a new Notebook in ArcGIS Online, navigate to the Notebook tab at the top of the home page. Either create a new Notebook or upload an existing one. Once created, open the Notebook to start configuring parameters. Python dictionaries consist of key-value pairs, which makes them useful for creating choice lists.


For example, the script used in this scenario checks a hosted feature layer for null or duplicate ID values, then updates the layer to ensure unique IDs. There are four hosted feature layers to choose from. Based on this, a dictionary called “HFL_dict” can be created, where the keys are layer names and the values are their REST URLs.



Configuring Input Parameters

To configure parameters, open the Parameters tab in the notebook editor. Both input and output parameters can be created. In this case, a single input parameter will be specified. Set the variable name, display name, and data type (string, in this case, since the dictionary keys are strings). Because the Notebook needs an input layer to successfully run, choose “Required” as the parameter type.


Next, select Choice List and enter the dictionary keys as the selectable options. Ensuring the key names exactly match those in the dictionary is essential to avoid errors. Once saved, the input parameter will be available for use within the script.




Integrating the Input Parameter in the Script

After configuring the parameter, insert it into the Notebook as a variable. Initially, it may display as "blank" (the default value). Once published as a tool, the user-selected value from the choice list will replace the placeholder. The Notebook will then access the corresponding hosted feature layer using the URL found in the dictionary.



Both the hosted feature layer dictionary and hosted feature layer key are passed through the function, and the user input key is used to select the hosted feature layer REST URL
Both the hosted feature layer dictionary and hosted feature layer key are passed through the function, and the user input key is used to select the hosted feature layer REST URL

Publishing and Using the Custom Web Tool

After testing the Notebook to ensure correct functionality, publish it as a custom web tool by clicking the Publish button at the top. The tool can then be incorporated into ArcGIS Web Maps and other ArcGIS web applications like Experience Builder.

In Experience Builder, the tool can be added using the Analysis widget. After configuration, the choice list will appear in the app, allowing users to select a layer. The chosen value will be passed to the script, which will then process the appropriate hosted feature layer based on the dictionary input.



The final tool output in the analysis widget in Experience Builder
The final tool output in the analysis widget in Experience Builder

By combining Python dictionaries with custom web tools, ArcGIS Online users can streamline workflows and provide dynamic, user-friendly tool interfaces. This approach enables the creation of intuitive, no-code interfaces, allowing other ArcGIS Online organization members to efficiently run custom tools without needing to interact with the underlying code.

bottom of page