Select to view content in your preferred language

Modifying existing dashboard via arcgis.apps.dashboard

2262
3
Jump to solution
06-21-2022 12:03 PM
JanTeisinger
Occasional Contributor

I am trying to modify an existing dashboard using arcgis.apps.dashboard Python module, but I am unable to create the Dashboard object from an existing item. I was searching for examples, but all documents I have seen only have directions how to create new dashboards. 

I am attempting to save all older dashboards to the new version 47+ using the Py API. I was hoping I can create the dashboard object from the existing older version of the dashboard and then use the .save() function. 

How can I modify an existing dashboard? 

The following code will fail, as it appears the Dashboard object does not allow passing in the item object from gis.content.get()

dashboard = Dashboard(item)
TypeError: __init__() takes 1 positional argument but 2 were given

 

    from arcgis.apps.dashboard import Dashboard
    item = gis.content.get("123456789abcdefgetc")
    dashboard = Dashboard(item)    
    print (dashboard.title)

 

 

1 Solution

Accepted Solutions
Clubdebambos
Frequent Contributor

Hi @JanTeisinger 

I recall attempting a similar task, you might only be able to create a new Dashboard object using the Dashboard module.

Maybe some of the workflow I have done previously might help figure some things out. I have a dashboard template and I export this as JSON and save to a .json file, in below script.

from arcgis.gis import GIS
import json

gis = GIS("home")

dsh_item = gis.content.get("***dsh_item_id***")

dsh_tem_data = dsh_item.get_data()

print(json.dumps(dsh_tem_data, indent=4, sort_keys=True))

You can manipulate this JSON in a notepad and then re-associate it to a copied version of the dashboard through an update.

from arcgis.gis import GIS
import json

## open the dashboard template json
## I'd have manipulated this to point to different datasets etc
with open(r"C:\path\to\file.json") as json_data:
    data = json.load(json_data)

# connect to AGOL
gis = GIS("home")

## the standard Dashboard template that the JSON was taken from
dsh_item = gis.content.get("***dsh_item_id***")

## copy and save the dashboard
new_dsh = dsh_item.copy(title="New_Title", tags="tag1,tag2,tag3", snippet='Enter summary', description='Enter desc')
dsh_data = new_dsh.get_data()

## apply new JSON to update the copied dashboard
item_properties = {"text":data}
new_dsh.update(item_properties=item_properties)

You will need to become familiar with how the JSON is formatted for a Dashboard, you can do this by creating different Dashboards an exporting the JSON to see how it all works. I haven't done much work with them myself but hopefully some of the stuff above is helpful.

~ learn.finaldraftmapping.com

View solution in original post

0 Kudos
3 Replies
Clubdebambos
Frequent Contributor

Hi @JanTeisinger 

I recall attempting a similar task, you might only be able to create a new Dashboard object using the Dashboard module.

Maybe some of the workflow I have done previously might help figure some things out. I have a dashboard template and I export this as JSON and save to a .json file, in below script.

from arcgis.gis import GIS
import json

gis = GIS("home")

dsh_item = gis.content.get("***dsh_item_id***")

dsh_tem_data = dsh_item.get_data()

print(json.dumps(dsh_tem_data, indent=4, sort_keys=True))

You can manipulate this JSON in a notepad and then re-associate it to a copied version of the dashboard through an update.

from arcgis.gis import GIS
import json

## open the dashboard template json
## I'd have manipulated this to point to different datasets etc
with open(r"C:\path\to\file.json") as json_data:
    data = json.load(json_data)

# connect to AGOL
gis = GIS("home")

## the standard Dashboard template that the JSON was taken from
dsh_item = gis.content.get("***dsh_item_id***")

## copy and save the dashboard
new_dsh = dsh_item.copy(title="New_Title", tags="tag1,tag2,tag3", snippet='Enter summary', description='Enter desc')
dsh_data = new_dsh.get_data()

## apply new JSON to update the copied dashboard
item_properties = {"text":data}
new_dsh.update(item_properties=item_properties)

You will need to become familiar with how the JSON is formatted for a Dashboard, you can do this by creating different Dashboards an exporting the JSON to see how it all works. I haven't done much work with them myself but hopefully some of the stuff above is helpful.

~ learn.finaldraftmapping.com
0 Kudos
JanTeisinger
Occasional Contributor

Hi, thank you for the tip and confirmation the dashboard module cannot manipulate an existing item. I am also using similar methods to manipulate the JSON directly, which work fine for most scenarios.

In this case I was hoping I could use the dashboard module to convert the older style JSON to the newer dashboard format, as we need to update specific design properties that are not present in the older format.

We actually got an answer directly from the ESRI dev team that JSON conversion is not possible, as the conversion logic is baked into the dashboard editor. Every time a dashboard is saved, it is now converted to the new JSON syntax. That means we will need to open all dashboards and manually hit save. 

Thank you!

0 Kudos
Clubdebambos
Frequent Contributor

Painful!

~ learn.finaldraftmapping.com
0 Kudos