user3626232
user3626232

Reputation: 189

Connect to delta table from a Dash Databricks App using Databricks Connect

I am building my first Dash app within Databricks Apps (Azure). I want to retrieve data from a delta table in the same account.

I have a cluster with a shared access mode and unrestricted policy which I am trying to connect to using Databricks Connect. The app deploys without error, but when I load it I get the error "There was a problem connecting to the upstream server."

import pandas as pd
from dash import Dash, dcc, html, dash_table, Input, Output, State
import plotly.express as px
import dash_bootstrap_components as dbc
from databricks.connect import DatabricksSession

# Initialize the Dash app with Bootstrap styling
dash_app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])

spark = DatabricksSession.builder.remote(
host       = f"https://adb-xxxxxxx.azuredatabricks.net",
cluster_id = "xxxx-xxxxxx-xxxxxxx"
).getOrCreate()

def get_delta_data():
    delta_df = spark.sql("""
                         SELECT * FROM myTable""")
    pandas_df = delta_df.toPandas()
    return pandas_df

df = get_delta_data()

dash_app.layout = html.Div(children=[

    html.H3('App'),
    dash_table.DataTable(
        id='db_table',
        columns = [{'name': i, 'id': i} for i in df.columns],
        data = df.to_dict("records"),
        page_size=10)
])

if __name__ == '__main__':
    dash_app.run_server(debug=True)

Upvotes: 1

Views: 31

Answers (0)

Related Questions