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!
Any chance you could share some of the code for troubleshooting?
Cheers,
Glen
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())
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.
Thank you for the questions!
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