Skip to main content

Embed a dashboard

This recipe embeds a Databricks AI/BI dashboard into a Databricks App.

Code snippet

app.py
import reflex as rx
import requests
from databricks.sdk.core import Config

# 1. Helper to fetch published dashboards from Databricks API
def get_published_dashboards():
cfg = Config()
headers = {"Authorization": f"Bearer {cfg.token}"}
# The Lakeview API endpoint for listing dashboards
url = f"{cfg.host}/api/2.0/lakeview/dashboards"

response = requests.get(url, headers=headers)
response.raise_for_status()

data = response.json()
published = {}
for d in data.get("dashboards", []):
if d.get("published"):
published[d.get("display_name")] = d.get("dashboard_id")
return published

class AiBiDashboardState(rx.State):
dashboard_options: dict[str, str] = {}
selected_dashboard: str = ""
iframe_source: str = ""

@rx.var
def dashboard_names(self) -> list[str]:
return list(self.dashboard_options.keys())

@rx.event
def on_load(self):
# Fetch available dashboards on load
self.dashboard_options = get_published_dashboards()
if self.dashboard_options:
# Default to the first one
self.selected_dashboard = self.dashboard_names[0]
self.update_src()

@rx.event
def set_selected_dashboard(self, value: str):
self.selected_dashboard = value
self.update_src()

def update_src(self):
# Construct the embed URL
cfg = Config()
dash_id = self.dashboard_options.get(self.selected_dashboard)
if dash_id:
self.iframe_source = f"{cfg.host}/dashboardsv3/{dash_id}/published?embed=true"
info

Copy and paste the dashboard embedding URL from the dashboard UI Share -> Embed iframe.

Resources

Permissions

Your app service principal needs the following permissions:

  • CAN VIEW permission on the dashboard
info

A workspace admin needs to enable dashboard embedding in the Security settings of your Databricks workspace for specific domains (e.g., databricksapps.com) or all domains for this sample to work.

Dependencies

requirements.txt
databricks-sdk
requests
reflex