Base: Access Tables via Python
Last updated
Was this helpful?
Was this helpful?
def fetch_data():
# Your data fetching and processing code here
# retrieving the Base oauth token
url = 'https://ica.illumina.com/ica/rest/api/projects/' + PROJECT_ID + '/base:connectionDetails'
# set the API headers
headers = {
'X-API-Key': API_KEY,
'accept': 'application/vnd.illumina.v3+json'
}
response = requests.post(url, headers=headers)
ctx = snowflake.connector.connect(
account=response.json()['dnsName'].split('.snowflakecomputing.com')[0],
authenticator='oauth',
token=response.json()['accessToken'],
database=response.json()['databaseName'],
role=response.json()['roleName'],
warehouse=response.json()['warehouseName']
)
cur = ctx.cursor()
sql = '''
WITH flattened_Demo_Ingesting_Metrics AS (
SELECT
flattened.value::STRING AS execution_reference_Demo_Ingesting_Metrics,
t1.SAMPLEID,
t1.VARIANTS_TOTAL_PASS,
t1.VARIANTS_SNPS_PASS,
t1.Q30_BASES,
t1.READS_WITH_MAPQ_3040_PCT
FROM
Demo_Ingesting_Metrics t1,
LATERAL FLATTEN(input => t1.ica) AS flattened
WHERE
flattened.key = 'Execution_reference'
) SELECT
f.execution_reference_Demo_Ingesting_Metrics,
f.SAMPLEID,
f.VARIANTS_TOTAL_PASS,
f.VARIANTS_SNPS_PASS,
t2."EXECUTION_REFERENCE",
t2.END_DATE,
f.Q30_BASES,
f.READS_WITH_MAPQ_3040_PCT
FROM
flattened_Demo_Ingesting_Metrics f
JOIN
BB_PROJECT_PIPELINE_EXECUTIONS_DETAIL t2
ON
f.execution_reference_Demo_Ingesting_Metrics = t2."EXECUTION_REFERENCE";
'''
cur.execute(sql)
data = cur.fetch_pandas_all()
return data
df = fetch_data()
app = Dash(__name__)
#server = app.server
app.layout = html.Div([
html.H1("My Dash Dashboard"),
html.Div([
html.Label("Select X-axis:"),
dcc.Dropdown(
id='x-axis-dropdown',
options=[{'label': col, 'value': col} for col in df.columns],
value=df.columns[5] # default value
),
html.Label("Select Y-axis:"),
dcc.Dropdown(
id='y-axis-dropdown',
options=[{'label': col, 'value': col} for col in df.columns],
value=df.columns[2] # default value
),
]),
dcc.Graph(id='scatterplot')
])
@callback(
Output('scatterplot', 'figure'),
Input('y-axis-dropdown', 'value')
)
def update_graph(value):
return px.scatter(df, x='END_DATE', y=value, hover_name='SAMPLEID')
if __name__ == '__main__':
app.run(debug=True)