|
1 | 1 | import streamlit as st |
2 | 2 | import streamlit.components.v1 as components |
| 3 | +import requests |
| 4 | +from databricks.sdk.core import Config |
3 | 5 |
|
4 | 6 | st.header("Data Visualization", divider=True) |
5 | 7 | st.subheader("AI/BI Dashboard") |
|
12 | 14 |
|
13 | 15 |
|
14 | 16 | 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.", |
19 | 50 | ) |
| 51 | + |
| 52 | + dashboard_id = final_published_dashboards.get(iframe_source_temp) |
20 | 53 |
|
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) |
22 | 57 | components.iframe(src=iframe_source, width=700, height=600, scrolling=True) |
23 | 58 |
|
24 | 59 | with tab_b: |
|
0 commit comments