Skip to content

Commit 5c58198

Browse files
scottDBX1886scottDBX1886
authored andcommitted
updated embedded dashboards to query for all available published dashboards that the app SP has access to
1 parent 9a59702 commit 5c58198

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

streamlit/views/embed_dashboard.py

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import streamlit as st
22
import streamlit.components.v1 as components
3+
import requests
4+
from databricks.sdk.core import Config
35

46
st.header("Data Visualization", divider=True)
57
st.subheader("AI/BI Dashboard")
@@ -12,13 +14,46 @@
1214

1315

1416
with tab_a:
15-
iframe_source = st.text_input(
16-
"Embed the dashboard:",
17-
placeholder="https://dbc-f0e9b24f-3d49.cloud.databricks.com/embed/dashboardsv3/01eff8112e9411cd930f0ae0d2c6b63d?o=37581543725667790",
18-
help="Copy and paste the URL from the dashboard UI Share -> Embed iframe.",
17+
18+
19+
cfg = Config()
20+
21+
host = cfg.host
22+
23+
token = list(cfg.authenticate().values())[0].split(" ")[1]
24+
url = f"{host}/api/2.0/lakeview/dashboards"
25+
headers = {
26+
"Authorization": f"Bearer {token}"
27+
}
28+
29+
response = requests.get(url, headers=headers)
30+
dashboards = response.json()
31+
dashboard_paths = {dashboard['display_name']: dashboard['dashboard_id'] for dashboard in dashboards['dashboards']}
32+
33+
published_dashboards = []
34+
35+
for dashboard in dashboards['dashboards']:
36+
dashboard_id = dashboard['dashboard_id']
37+
38+
published_url = f"{host}/api/2.0/lakeview/dashboards/{dashboard_id}/published"
39+
response = requests.get(published_url, headers=headers)
40+
41+
if response.status_code == 200:
42+
published_dashboards.append((dashboard['display_name'], dashboard['dashboard_id']))
43+
print( dashboard['display_name'] + ' ' + dashboard['dashboard_id'])
44+
final_published_dashboards = {k: v for k, v in published_dashboards }
45+
46+
#st.info(final_published_dashboards)
47+
iframe_source_temp = st.selectbox(
48+
"Select your AI/BI Dashboard:", [""] + list(final_published_dashboards.keys()),
49+
help="Dashboard list populated from your workspace using app service principal.",
1950
)
51+
52+
dashboard_id = final_published_dashboards.get(iframe_source_temp)
2053

21-
if iframe_source:
54+
if iframe_source_temp and iframe_source_temp != "":
55+
iframe_source = f"{host}/embed/dashboardsv3/{dashboard_id}"
56+
#st.info(iframe_source)
2257
components.iframe(src=iframe_source, width=700, height=600, scrolling=True)
2358

2459
with tab_b:

0 commit comments

Comments
 (0)