Creating Widgets through Scripting

I’m working with a dashboard in perspective. I’d like to be able to add new widgets through scripting. I’m not exactly sure how to create new widget instances through.
My end goal is to be able to load a dashboard’s configuration from a database based on a button press but I’m stuck on the creating widgets from scripting part.

Start by using Designer.

  • Create a view - if you haven’t already - to use as a widget.
  • Add it to props.availableWidgets.0 and give props.availableWidgets.0.name a value. (e.g. ‘CheckBox’.)
  • Run the designer, click the pencil semi-circle at the bottom and add a couple of instances of your widget.
  • Right click on props.widgets and copy the JSON.
  • Paste it into your favourite text editor and you should see something like,
props.widgets JSON
[
  {
    "name": "CheckBox",
    "viewPath": "coordChkBox",
    "viewParams": {},
    "isConfigurable": true,
    "header": {
      "enabled": true,
      "title": "",
      "style": {
        "classes": ""
      }
    },
    "body": {
      "style": {
        "classes": ""
      }
    },
    "minSize": {
      "columnSpan": 1,
      "rowSpan": 1
    },
    "position": {
      "rowStart": 3,
      "rowEnd": 6,
      "columnStart": 4,
      "columnEnd": 7
    },
    "style": {
      "classes": ""
    }
  },
  {
    "name": "CheckBox",
    "viewPath": "coordChkBox",
    "viewParams": {},
    "isConfigurable": true,
    "header": {
      "enabled": true,
      "title": "",
      "style": {
        "classes": ""
      }
    },
    "body": {
      "style": {
        "classes": ""
      }
    },
    "minSize": {
      "columnSpan": 1,
      "rowSpan": 1
    },
    "position": {
      "rowStart": 2,
      "rowEnd": 4,
      "columnStart": 1,
      "columnEnd": 3
    },
    "style": {
      "classes": ""
    }
  }
]

Now you just have to script the creation of that!

I had no idea you could alter configs that way. Thanks so much for your help!