> For the complete documentation index, see [llms.txt](https://dev.ubidots.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dev.ubidots.com/sdks/dashboard-runtime-library.md).

# Dashboard runtime library

## Overview

The *Dashboard Runtime Library* written in [React](https://es.react.dev/), is the backbone that enables building applications within Ubidots with the capability of interacting with dashboard data, events and the Ubidots API.

## Getting started

### Add the library to your project

Run the following command at the root of the project where you want to add the library

{% tabs %}
{% tab title="PNPM" %}

```bash
pnpm add @ubidots/react-html-canvas
```

{% endtab %}

{% tab title="Yarn " %}

```bash
yarn add @ubidots/react-html-canvas
```

{% endtab %}
{% endtabs %}

#### Peer Dependencies

* react >= 16.8
* react-dom >= 16.8

### Usage

Wrap your app with the Provider and use hooks to access dashboard data/event

```js
import 
  UbidotsProvider,
  useUbidotsReady,
  useUbidotsSelectedDevice,
  useUbidotsActions,
} from '@ubidots/react-html-canvas';

function DeviceInfo() {
  const ready = useUbidotsReady();
  const device = useUbidotsSelectedDevice();
  const { setDashboardDevice } = useUbidotsActions();

  if (!ready) return <span>Loading...</span>;
  return (
    <div>
      <pre>{JSON.stringify(device, null, 2)}</pre>
      <button onClick={() => setDashboardDevice('device-id')}>
        Select Device
      </button>
    </div>
  );
}

export default function App() {
  return (
    <UbidotsProvider readyEvents={['receivedToken']}>
      <DeviceInfo />
    </UbidotsProvider>
  );
}
```

## API & examples

To build a dashboard widget with this library, see [Custom Metric](/dashboards-and-widgets/custom-metric.md). Each [dashboard capability](/dashboards-and-widgets/custom-metric/dashboard-capabilities.md) has its own page with the exact payload shapes and a snippet:

* [Widget data](/dashboards-and-widgets/custom-metric/dashboard-capabilities/widget-data.md): `useWidgetEvents()` `onInfo` / `onData`.
* [Devices](/dashboards-and-widgets/custom-metric/dashboard-capabilities/devices.md): `dashboardDevices`, `useUbidotsSelectedDevice()`, `setDashboardDevice()`.
* [Date range](/dashboards-and-widgets/custom-metric/dashboard-capabilities/date-range.md): `useUbidotsDashboardDateRange()`, `setDashboardDateRange()`.
* [Real-time](/dashboards-and-widgets/custom-metric/dashboard-capabilities/real-time.md): `useUbidotsRealTimeStatus()`, `setRealTime()`.
* [Dashboard actions and filters](/dashboards-and-widgets/custom-metric/dashboard-capabilities/dashboard-actions.md): `refreshDashboard()`, `setFullScreen()`, `openDrawer()`, `setDashboardLayer()`, `useUbidotsSelectedFilters()`.
* [Widget events](/dashboards-and-widgets/custom-metric/dashboard-capabilities/widget-events.md): `emitWidgetEvent()`, `onWidgetEvent()`, `onAnyWidgetEvent()`.

For the full list of hooks and actions the library exposes, see the project's [repo](https://github.com/ubidots/react-html-canvas?tab=readme-ov-file).


---

# 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://dev.ubidots.com/sdks/dashboard-runtime-library.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.
