> For the complete documentation index, see [llms.txt](https://www.opal-rt.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.opal-rt.com/docs/rt-lab/simulation-control-monitoring-and-logging/interact-using-dashboards/dashboards-scripting-and-api.md).

# Dashboards Scripting & API

Scripts in Dashboards enable users to leverage Python directly within the platform. Dashboards provide a **Python API** and a dedicated environment for executing scripts seamlessly. The Scripts interface is accessible from the Navigation pane and consists of the **Script List**, **Script Editor**, and **Logs**.

For more information, refer to [**Automation, API & Scripting**](https://www.opal-rt.com/docs/rt-lab/automation-api-and-scripting/introduction-to-automation.md) section.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-cda97e2404219d8d8ed3300e5a79515d9332ea46%2FDH-api.png?alt=media" alt=""><figcaption></figcaption></figure>

## Add a new script

To create a new script, click the **+** button in the Script List. A template script will be generated, showing how to access the current project, the entry point of the API. For more details on Python API capabilities, refer to the \[Class Reference].

## Edit a script

Scripts can be edited directly in Dashboards or in an external environment. Changes are automatically saved when editing within Dashboards.

## Run a script

To execute a script, either:

* Click the **Run** button in the Script List, or
* Click the **Run Script** button in the Script Editor.

Logs displayed in the Logs pane are contextualized for the selected script. Only the most recent log for each script is saved.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-a6b21bf76b7407423e8f5bbf716cfe019de28fa9%2FDH-script.gif?alt=media" alt=""><figcaption></figcaption></figure>

## Trig a script from a button widget

A **Button** widget in a panel can trigger a script in **Operate** mode, whether or not a simulation is running. Multiple scripts can run simultaneously, but only one instance of the same script may execute at a time. The execution order of multiple scripts is not guaranteed and may lead to conflicts.

<figure><img src="https://96827845-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FNRdpSk8kjn20gXAexnt6%2Fuploads%2Fgit-blob-99036cbff35f9481e242cd9e065d63b44bde7497%2FDH-trig-button.gif?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## Limitations

**Script Execution**

* Only one instance of the same script can run at a time.
* Editing a script while it is running is not supported.

**Script Restrictions**

* User-defined script imports are not supported.
* Third-party Python packages are not allowed.
* The `if __name__ == "__main__"` construct is not supported.

**Console Limitations**

* Certain built-in Python functions (e.g., `input()`) cannot be used, as there is no interactive console in Dashboards.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.opal-rt.com/docs/rt-lab/simulation-control-monitoring-and-logging/interact-using-dashboards/dashboards-scripting-and-api.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
