5X Data Apps: Connecting to Google BigQuery

A guide to build Streamlit apps with Google BigQuery in your 5X workspace

Prerequisites

Before you start building your Streamlit app with BigQuery:
Workspace Setup
Ensure your 5X workspace is configured with Google BigQuery as the warehouse
App Connection
Confirm that both Credentials and App Connection for Data Apps is set up in your settings page.
Make sure you have the necessary permissions to access BigQuery datasets

Setting Up Your Streamlit App

Add Required Library
In 5X Data Apps UI: Select 5x-google-bigquery-auth-manager from the library dropdown
OR
Add to your requirements.txt:
5x-google-bigquery-auth-manager
Authentication Authentication is automatically handled by 5X platform using your workspace configuration. No additional credential setup is required.

Quick Start Code

Copy this template to quickly create a Streamlit app that connects to your workspace's BigQuery instance:
python
Copy
import streamlit as st
from bigquery_auth import create_bigquery_client
import pandas as pd

# Initialize BigQuery client - uses your workspace's configuration
client = create_bigquery_client()

# Create your Streamlit interface
st.title("5X BigQuery Data Explorer")

# Example query - replace with your dataset and table names
query = """
SELECT column1, column2
FROM `your-project.dataset.table`
LIMIT 10
"""

if st.button("Run Query"):
try:
# Execute query
df = client.query(query).to_dataframe()
st.dataframe(df)
except Exception as e:
st.error(f"Query failed: {str(e)}")

Best Practices

Use parameterized queries to prevent SQL injection
Implement error handling for failed queries
Set appropriate query limits to manage resource usage
Cache results for frequently accessed data
Follow Streamlit's performance optimization guidelines

Troubleshooting

Common issues and solutions:
Connection Failed: Verify workspace BigQuery connection in Settings
Permission Denied: Check dataset access permissions in your BigQuery workspace
Query Timeout: Consider optimizing your query or adding limits
Query Error: Verify table names and SQL syntax

Support

For technical assistance:
Email
Visit our

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.