ArcGIS Online

Use Parameters in your Scheduled Notebooks

In a previous blog article, we showed you a detailed example of using ArcGIS Notebooks in “Scheduled Mode”, which is brand new functionality in the April 2021 release of ArcGIS Online.  Our example was to schedule a notebook to run once a day, which downloads an online dataset from a URL, performs some data engineering on it, then produces a hosted feature layer in our organization. As part of this new built-in scheduling functionality, you also have the ability to insert parameters into the notebook, which are applied upon notebook execution.  Here are some examples of use cases for scheduling parameters:

In the following example, we’ll highlight two of these use cases: First, we’ll set up some parameters to insert ArcGIS organization credentials in a notebook, then add another parameter that allows us to filter a dataset in our notebook based on a query.  Inserting these parameters makes our scheduled notebooks more flexible, in that we can change the code and results without actually changing the code.  When using notebooks in scheduled mode, the parameters are the only place where there is any user interaction with the notebook.

How to set up parameters in a scheduled notebook?

When you create a task to schedule, one of the very first options you see is to set parameters.  However, the workflow for creating parameters actually starts in the notebook that you want to schedule.

Step 1: Decide which notebook values you want to be able to change using parameters.  In my case, I want to use parameters to hide the username and password to log into my GIS, as well as a parameter to filter my US county-level dataset to a particular state.

Username and password values to change.
State name to change.

Step 2: Insert a new code cell above the cell that contains the values you want to change.

Step 3: From the View dropdown, choose Cell Toolbar, then Tags.  You’ll see a bar appear above each cell in the notebook.

Step 4: On the right side of the newly added cell, name the cell “injected-parameters”, then click Add tag.  It has to be named this way for the parameters to work.

Step 5: In the parameters cell, create variables representing the parameters you want to inject into your notebook.  At this point, it does not really matter what the variable values are, as these will be changed from the Tasks pane when scheduling the notebook.

Step 6: Save the notebook.

Step 7: Create a Task from the top ribbon to schedule this notebook.

Step 8: After naming the task, add the key and value pairs that represent the variables and values you want to inject as parameters in the notebook.

Note: the keys have to be exactly the same as the variables you added into the parameters cell.  Also, make sure that you click the + sign after adding each key value pair.

These key value pairs represent the values that will be injected into the notebook, which will override the values we used in the parameters cell we added in Step 5.  In our case, the username (“un”) and password (‘pw’) values will be replaced by my ArcGIS Online credentials (“nich7905”/”password”), and the state_param value (“state name”) will be replaced with “Pennsylvania”.

If you toggle on Save Parameters to Notebook, the parameters you typed into the Create Task dialog will be injected into the notebook, and they will be added as a new cell in the notebook.  Because the username/password is sensitive information, we do not want it to be included in the notebook after it is run, so we will keep the Save Parameters to Notebook toggled off.

Step 9: After clicking next, you can fill out the task schedule details, which we discussed in detail in this blog post.

You can view your completed tasks by viewing the task details.

The first example shows the results of an executed notebook in which I did not save parameters, which is ideal for a workflow where you do not want certain information visible (e.g. passwords) when you view the HTML preview of the notebook.

The second example shows the results of an executed notebook where I chose to save the parameters to the notebook.  Notice that the parameters are injected as a new cell in the notebook.

Join the GeoNet Community

Whether you want to talk about parameterization in scheduled notebooks, or ArcGIS Notebooks in Online, Enterprise, or Pro in general, please join the ArcGIS Notebooks community . Ask questions, share ideas, and get help from your fellow notebook users. You can also visit the ArcGIS Notebooks product page for product level information and quick links to resources.

About the author

Nick Giner is a Product Manager for Spatial Analysis and Data Science. Prior to joining Esri in 2014, he completed Bachelor’s and PhD degrees in Geography from Penn State University and Clark University, respectively. In his spare time, he likes to play guitar, golf, cook, do yard work, and read/watch shows about history.


Leave a Reply

Please Login to comment

Next Article

What's New in ArcGIS Enterprise 10.9: Administrative Reports

Read this article