Select to view content in your preferred language

AGOL Notebook webtool parameters

919
4
08-14-2024 12:10 PM
HaydnLawrenceMoncton
New Contributor

I am trying to get the item id from a "File" input parameter in my AGOL notebook's published webtool. The CSV is brought in no problem as I can access it, get the data, and output a new CSV. However, I have manually added the itemID to my code and would rather be able to access it from the input parameter of the chosen CSV. 

I know it's probably a quick answer, but can't find it in the documentation. 

Also, if anyone knows how to send output to the final results window of a webtool in AGOL similar to how arcpy.AddMessage does for a normal geoprocessing tool, that would be great. 

My variable is added to the notebook:
data_csv = {
  "dataType": "GPDataFile",
  "paramName": "data_csv",
    "value": {
    "url": ""
  }
}

 

And right now I am just using this itemid hardcoded to access and download the file to put in a pandas dataframe. What I would like is something like "data_csv.value.itemid" or something similar instead of the hardcoded itemid value.

item_id = '38f3XXXXXXXX...'
item = gis.content.get(item_id)
csv_data = item.download(file_name='data.csv')

# Load the CSV into a Pandas DataFrame
with open(csv_data, 'r') as file:
  data_pd = pd.read_csv(file)
  print(data_pd.head())

 


Thanks!

0 Kudos
4 Replies
Clubdebambos
MVP Regular Contributor

Hi @HaydnLawrenceMoncton,

Any chance you could share some of the code for troubleshooting?

Cheers,

Glen

~ learn.finaldraftmapping.com
0 Kudos
HaydnLawrenceMoncton
New Contributor

My variable is added to the notebook:
data_csv = {
  "dataType": "GPDataFile",
  "paramName": "data_csv",
    "value": {
    "url": ""
  }
}

 

And right now I am just using this itemid hardcoded to access and download the file to put in a pandas dataframe. What I would like is something like "data_csv.value.itemid" or something similar instead of the hardcoded itemid value.

item_id = '38f3XXXXXXXX...'
item = gis.content.get(item_id)
csv_data = item.download(file_name='data.csv')

# Load the CSV into a Pandas DataFrame
with open(csv_data, 'r') as file:
  data_pd = pd.read_csv(file)
  print(data_pd.head())

 

Clubdebambos
MVP Regular Contributor

I also could not get the WebTool to take a CSV item as input or a url to a CSV file and directly access the item/csv data from the input parameter.

~ learn.finaldraftmapping.com
0 Kudos
xlt208
by Esri Contributor
Esri Contributor

Hi @HaydnLawrenceMoncton,

Thank you for the questions!

  1. Notebook web tools currently do not have an equivalent to arcpy.AddMessage(), but I have noted that this feature will be desired. For the time being, the closest alternative is to create a string output parameter that includes the messages you would like to pass on to the web tool users.
  2. To input an item ID to a web tool, you can create a string input parameter to obtain the item ID from the web tool users. Then, you can include logic to validate the item and proceed to the next steps. For example: 
input_csv_item_id = "<item-id-from-user>" # input parameter

from arcgis.gis import GIS
gis = GIS("home")

input_item = gis.content.get(input_csv_item_id)

if not input_item:
    raise Exception(f"Unable to find an item matching the input ID '{input_csv_item_id}'.")
elif input_item.type != "CSV":
    raise Exception(f"The input ID '{input_csv_item_id}' does not refer to a CSV item.")​

csv_data = input_item.download(file_name="data.csv")
with open(csv_data, "r") as file:
  data_pd = pd.read_csv(file)

 

I hope this helps!

 

Lingtao

Product Engineer for ArcGIS Notebooks 

 

0 Kudos