Overview
The Lightdash React SDK (@lightdash/sdk) provides React components for embedding Lightdash content in your React or Next.js applications. The SDK offers advantages over iframe embedding:
- Seamless integration with your React application
- Programmatic filters for dashboards
- Callbacks for user interactions (e.g., explore navigation)
- Custom styling to match your application
- TypeScript support with full type definitions
Set up CORS
To use the React SDK, you need to update your “Cross-Origin Resource Sharing” (CORS) policy so the domain hosting your React app is allowed to call the Lightdash API. In Lightdash, go to Project settings -> Embed configuration -> CORS and add the origins where you will use the SDK, for examplehttps://app.example.com or *.example.com.
For self-hosted deployments, you can also configure instance-level allowed origins with environment variables:
LIGHTDASH_CORS_ENABLED=false only if you want to disable CORS for the whole instance.
Why CORS is neededEnabling CORS (Cross-Origin Resource Sharing) is necessary because browsers enforce security policies that prevent web applications from making requests to a different domain than the one that served the app (known as the Same-Origin Policy).Since the Lightdash React SDK interacts with a Lightdash API, you need to configure CORS on your Lightdash instance to allow your frontend application to communicate with the Lightdash server without being blocked by the browser.
Installing the Lightdash SDK
In your frontend project, use your preferred package manager to install the SDK.At the moment, we support React 18 and 19, so make sure your frontend is using React 18 or later.
For Next.js, version 15 or later is required.
Import CSS styles
The Lightdash SDK requires CSS styles to render components correctly. Import the SDK’s CSS file as the first import in your React application’s entry point:Components and hooks
The Lightdash SDK exports components for embedding Lightdash content and hooks for building custom host-app UI around embedded content:Lightdash.Dashboard- Embed complete dashboards with multiple tilesLightdash.DashboardBuilder- Let embedded users create a brand-new dashboardLightdash.Chart- Embed individual saved chartsLightdash.Explore- Embed interactive data exploration interfaceLightdash.AiAgent- Embed an AI agent so users can chat with their dataLightdash.MetricsCatalog- Embed the project metrics catalog so users can browse and explore metricsLightdash.useLightdashContent- List spaces, dashboards, charts, and data apps for a custom content catalogLightdash.useLightdashAiAgentThreads- List an embed user’s previous AI agent threads to build a thread history UI
Lightdash.Dashboard
Embed complete Lightdash dashboards with multiple visualizations, filters, and interactive features.Props
Basic usage
With filters
Apply filters programmatically using thefilters prop:
With styling
With explore callback
Track when users navigate to explore:With edit mode
When the JWT includes awriteActions claim, you can render an existing dashboard in edit mode and let users rename it, add saved charts from the allowed space, move or resize tiles, and save changes. The host app controls the edit-mode state through isEditMode and onEditModeChange.
writeActions.spaceUuid, so users can only pick saved charts from the allowed space. See Write actions for the JWT claim.
Lightdash.DashboardBuilder
Let embedded users build a brand-new dashboard from scratch. On mount, the SDK creates an empty dashboard in the JWTwriteActions.spaceUuid and renders it through the same embedded dashboard component as Lightdash.Dashboard. The host app controls when the dashboard is in edit mode.
Use this when you want your customers to author their own dashboards inside your app — for example, a “Create dashboard” page in your customer portal — without giving them a Lightdash login.
Props
Basic usage
Requirements and behavior
- The JWT must include a
writeActionsclaim withspaceUuid. JWTs withoutwriteActionsfail closed for write-capable paths. - The new dashboard is created in
writeActions.spaceUuid, named “Untitled dashboard”, and is empty. - Add-tile content (saved charts and SQL charts) is filtered to the same space.
- Dashboards created or edited through the SDK are normal Lightdash dashboards — they can be viewed and edited from Lightdash and vice versa.
- See Write actions for the JWT claim and how to configure the actor and destination space.
Lightdash.Chart
Embed individual saved charts for focused, single-metric displays with minimal UI.Props
Unlike Dashboard, Chart does not support
filters or onExplore props since charts are read-only and cannot navigate to explore.Basic usage
With styling
Token generation for charts
Charts require a JWT withtype: 'chart':
Lightdash.Explore
Embed interactive data exploration interface with full query builder capabilities.Props
Basic usage
With styling
Token generation for explores
Explores requirecanExplore: true in the JWT:
Lightdash.AiAgent
Embed a Lightdash AI agent so embedded users can chat with their data, generate charts, and save results back to a fixed space — without a Lightdash login. The component renders the agent inside an iframe. UsethreadUuid to deep-link into an existing thread, or omit it to land on the new-thread screen.
Props
Lightdash.AiAgent does not accept filters, contentOverrides, or onExplore. Threads, navigation, and chart actions are managed inside the embedded agent UI.onThreadChange fires whenever the embedded agent creates a new thread or opens an existing one. Use it together with threadUuid to persist the current conversation in your app (for example in localStorage or your own backend) and resume it the next time the user returns. Under the hood, the SDK passes a targetOrigin query parameter to the iframe and listens for lightdash:aiAgentThreadChanged postMessage events from the embedded page — no extra setup is required on your side.
Basic usage
Open a specific thread
PassthreadUuid to deep-link the embed into a specific conversation on mount:
Persist and resume the last conversation
CombinethreadUuid and onThreadChange to keep users on their most recent thread across page reloads. This example stores the latest thread UUID in localStorage:
Token generation for AI agents
AI agent embeds require a JWT withcontent.type: 'aiAgent' and a writeActions claim that pins the destination space and the actor used for agent queries and chart saves:
Lightdash.MetricsCatalog
Embed the Lightdash metrics catalog so embedded users can browse the metrics defined in a project, preview them, and — when the JWT allows it — continue into Explore without leaving your app. The component renders the catalog inside an iframe. When a viewer clicks Explore from here on a metric, the SDK swaps in an embedded Explore view; a Back action returns them to the catalog.Props
Lightdash.MetricsCatalog does not accept filters, contentOverrides, or onExplore. The catalog and the embedded Explore it launches are managed inside the component.Basic usage
Token generation for the metrics catalog
Metrics catalog embeds require a JWT withcontent.type: 'metricsCatalog' and a projectUuid. Set content.canExplore to true to let embedded users open Explore from a metric, and include a writeActions claim if you want them to save the resulting charts back to Lightdash.
canExplore (or set it to false) to publish a read-only browse experience. See Embedding the metrics catalog for the full guide and Metrics catalog token for the complete JWT structure.
API hooks
Lightdash.useLightdashContent
UseuseLightdashContent when you want your own app to list Lightdash content instead of embedding the Lightdash home page. A common pattern is to let customers choose a space in your UI, show the dashboards and charts in that space, then render the selected object with Lightdash.Dashboard or Lightdash.Chart.
The hook calls the Lightdash content API and returns metadata only. It does not render the selected chart or dashboard, and it does not replace the chart or dashboard embed token you pass to the render component.
Backend: generate an API access token
Generate the token on your backend with your Lightdash embed secret. Never expose the embed secret in browser code.Frontend: list content in a space
Options
Use the
spaceUuids option as a filter, not as an authorization boundary. Authorization comes from the API access token’s service account permissions.Lightdash.useLightdashAiAgentThreads
UseuseLightdashAiAgentThreads when you want to show your users a list of their previous AI agent conversations — for example a “Recent chats” sidebar next to a Lightdash.AiAgent embed. The hook calls the AI agent threads endpoint with the embed JWT, so it returns only threads that belong to the JWT-authenticated embed user and are scoped to their embed space.
Pair it with Lightdash.AiAgent’s threadUuid and onThreadChange props to let users resume any past conversation.
Options
LightdashApiClientConfig as useLightdashContent, with auth.type: 'embedToken' and the AI agent embed JWT as the token.
Types
Example: thread history + resume
useLightdashAiAgentThreads uses the same embed JWT you pass to Lightdash.AiAgent. The token’s content.agentUuid and writeActions.spaceUuid are what scope the returned threads — the hook cannot list threads from a different agent or space, even if you pass a different agentUuid argument.Generating embed tokens
All SDK components require JWTs generated server-side. Here’s a complete example:Backend API endpoint
Frontend React component
Applying styles
Override styles within Lightdash components to match your application’s design.Supported style overrides
styles object passed to any component.
Font family
Sets the font family for all text within the embedded content. Font sizes and other properties are preserved.Some charts and components set
font-family explicitly, so the fontFamily style is applied with higher specificity to override these.Background color
Sets the background for the embedded content. Can be any color value or'transparent'.
Complete example
CSS class overrides
Beyond thestyles prop, you can target embedded dashboard elements directly from your application’s stylesheet. Each element below carries a stable, human-readable classname that is part of the SDK’s public API — it won’t change when internal layout does, so your overrides stay resilient across releases.
| Class | Element |
|---|---|
ld-dashboard-header | The dashboard header bar |
ld-dashboard-filters | The filter bar row |
ld-dashboard-filter | An individual filter pill |
ld-dashboard-date-zoom | The date-zoom control(s) |
ld-dashboard-parameters | The parameters row |
ld-dashboard-parameter | An individual parameter pill |
ld-dashboard-filter-dropdown | An open filter’s dropdown |
ld-dashboard-date-zoom-dropdown | The open date-zoom menu |
ld-dashboard-parameter-dropdown | An open parameter’s dropdown |
The filter, date-zoom, and parameter dropdowns render in a portal at the page root — outside the dashboard container — so target them with a global selector rather than as a descendant of the embedded dashboard.
Light and dark mode
Use thetheme prop to render embedded content in either 'light' or 'dark' mode. This is typically driven by the host application’s own theme state, so the embedded dashboard, chart, or explore matches the surrounding UI.
theme prop is supported on Lightdash.Dashboard, Lightdash.Chart, and Lightdash.Explore.
When
theme is set, the SDK forces the Mantine color scheme and ignores any user-toggled preference stored in the embed. Omit the prop to let the embed use its default (light) color scheme.Syncing with your app’s theme
Pass your app’s current theme value directly to the SDK so the embed re-renders when it changes:Combining with styles.backgroundColor
When theme is set, the embed uses the matching Mantine body background by default. If you also pass styles.backgroundColor, your value takes precedence:
Color palettes
You can customize the appearance of embedded dashboards using color palettes. Define multiple color palettes in your organization settings, then apply them to embedded dashboards using thepaletteUuid prop.
For more on customizing appearance, see customizing the appearance of your project.
Setting up color palettes
- Go to Organization settings > Appearance in Lightdash
- Define one or more color palettes
- Copy the palette UUID for the palette you want to use (or fetch from API
GET /api/v1/org/color-palettes)
Applying a palette
Pass thepaletteUuid prop to the Lightdash.Dashboard component:
Filtering data
Filters can be passed to<Lightdash.Dashboard/> to filter dimensions by values. Filters are applied as AND operations, each further restricting results.
Filtering is only available for Dashboard components. Chart and Explore components do not support the
filters prop.Filter structure
Basic example
Multiple filters
Filters are applied as AND operations:FilterOperator enum
ImportFilterOperator from the SDK:
| Operator | Description | Value Type |
|---|---|---|
FilterOperator.IS_NULL | Field is null | n/a |
FilterOperator.NOT_NULL | Field is not null | n/a |
FilterOperator.EQUALS | Field equals value | single value |
FilterOperator.NOT_EQUALS | Field does not equal value | single value |
FilterOperator.STARTS_WITH | Field starts with value | single value |
FilterOperator.ENDS_WITH | Field ends with value | single value |
FilterOperator.INCLUDE | Field includes any of values | array |
FilterOperator.NOT_INCLUDE | Field does not include values | array |
FilterOperator.LESS_THAN | Field is less than value | single value |
FilterOperator.LESS_THAN_OR_EQUAL | Field is ≤ value | single value |
FilterOperator.GREATER_THAN | Field is greater than value | single value |
FilterOperator.GREATER_THAN_OR_EQUAL | Field is ≥ value | single value |
FilterOperator.IN_THE_PAST | Date in the past N units | single value |
FilterOperator.NOT_IN_THE_PAST | Date not in past N units | single value |
FilterOperator.IN_THE_NEXT | Date in the next N units | single value |
FilterOperator.IN_THE_CURRENT | Date in current period | single value |
FilterOperator.NOT_IN_THE_CURRENT | Date not in current period | single value |
FilterOperator.IN_BETWEEN | Field between two values | array with 2 values |
FilterOperator.NOT_IN_BETWEEN | Field not between values | array with 2 values |
Available fields
Only fields that are available for filtering can be filtered. These are specified in the JWT passed to the SDK.To generate tokens with filterable fields, configure your embed in the Lightdash UI or include the appropriate fields in your JWT structure.
Localization
The Lightdash SDK supports multilingual translation using standard i18n translation objects. To display a translated Lightdash dashboard, pass a correctly formatted translation object to the SDK.Recommended tools
- Translation maps – The Lightdash CLI can generate translation maps when downloading content as code
- Runtime translation management – Use a translation library like
i18next - Translation production tools – Tools like Locize help manage translations efficiently
Video overview
Translation maps
The Lightdash CLI can produce translation maps for dashboards and charts. To include translation maps when downloading content, add the--language-map flag:
<file name>.language.map.yml file containing translatable strings.
Example translation map:
Runtime translation
At runtime, pass a translation object to the SDK’scontentOverrides prop. We suggest using i18Next to load translations:
Setting up i18Next with Locize
What can be translated
Can be translated (UI strings specified in Lightdash):- Dashboard names and descriptions
- Tile titles
- Chart names
- Axis labels
- Series names
- Markdown content
- String values in charts
- Dimension values
- Metric names from database
- Raw data in tables
Strings originating from your data warehouse cannot be translated by the SDK. They are presented as they exist in your database.
Complete example
Here’s a full example integrating everything:Backend (Express + Node.js)
Frontend (React)
See also
Embedding quickstart
Get started with embedding in 5 minutes
Embedding API reference
Complete JWT structure and configuration
iframe embedding reference
Complete iframe URL patterns and HTML embedding
Embedding dashboards
Complete guide to dashboard embedding
Embedding charts
Complete guide to chart embedding
User attributes
Implement row-level security with user attributes