Squadbase

Why Build BI Dashboards with Streamlit

The Transformation from Traditional BI Tools to Code-Based Approaches

This book is written by the development team at Squadbase. Squadbase is a platform for building and deploying code-driven internal tools. By combining rapid AI-assisted development with streamlined deployment, it helps companies turn data into productivity gains.

Throughout this book, we focus on "building BI dashboards with Streamlit."

Introduction

While BI (Business Intelligence) tools are crucial for data-driven decision-making, traditional platforms present limitations that many companies are now encountering. As a result, building BI dashboards with code, particularly using Streamlit, is gaining traction.

This chapter outlines the challenges of traditional BI tools and explains why Streamlit offers a compelling alternative.

Challenges of Traditional BI Tools

Limited Customization

Traditional BI tools restrict users to vendor-provided features, making it difficult to integrate custom logic or advanced AI models. Developing custom UI and features tailored to specific operational needs is a common challenge.

Data Source Limitations

BI tools often have constraints on the format and volume of data they can handle:

  • Connectivity is typically limited to a handful of databases, preventing direct access to SaaS APIs.
  • Performance degrades as data volume increases, leading to slow dashboard loading.
  • Handling nested data structures like JSON or XML requires extensive data preprocessing.

High Learning Costs

Many BI tools have complex user interfaces that require significant training for non-engineers. Users must learn tool-specific methods, making knowledge transfer within teams difficult.

Difficulty in Making Changes

Modifying BI dashboards often requires specialized engineers, slowing down response times to changing business requirements and potentially leading to missed opportunities.

Poor Maintainability

Configuration and customization in many BI tools are done through a GUI, which complicates version control. Tracking changes or rolling back to a previous state can be difficult. Furthermore, inadequate support for multiple environments increases maintenance overhead.

High Operational Costs

BI tool license fees are often tied to the number of users and data capacity. The costs of hiring and training specialized personnel are also significant.

To address these issues, companies are increasingly adopting code-based approaches ("BI as Code"). Streamlit, in particular, is emerging as a popular framework for building BI dashboards due to its simplicity and flexibility.

Code-Based Solutions with Streamlit

Example of a dashboard built with Streamlit

What is Streamlit?

Streamlit is an open-source Python framework for building data applications. Its key feature is the ability to create interactive web applications with minimal code.

import streamlit as st
import pandas as pd

st.title("Sales Dashboard")
data = pd.read_csv("sales_data.csv")
st.line_chart(data)

A functional dashboard can be created with just a few lines of code.

Key Benefits of Streamlit

1. Simple Learning Curve

Analysts with basic Python knowledge can start building dashboards quickly. Existing data analysis skills are directly transferable to dashboard development.

2. Flexibility and Customization

A code-based approach offers significant freedom:

  • Extensive Customization: Build UIs that precisely match business requirements.
  • Modern Technology Integration: Freely integrate AI models and cloud services.
  • Custom Logic Implementation: Accurately model complex business rules.

3. Version Control and Collaboration

Using Git for code management provides several advantages:

  • Complete Change History: All modifications are tracked with clear accountability.
  • Efficient Team Development: Parallel work and merging using branches.
  • Improved Quality Management: Quality assurance through code reviews.

Case Studies

Use CaseTraditional ChallengesSolution with Streamlit
Manufacturing: Quality Control Dashboard
  • Inability to model complex quality standards.
  • Lack of real-time monitoring for defect detection.
  • Implementation of custom quality evaluation logic.
  • Real-time data monitoring from IoT sensors.
  • Automated alerts using anomaly detection algorithms.
E-commerce: Sales Analysis Dashboard
  • Difficulty integrating data from multiple sources (web, mobile, stores).
  • Inability to incorporate predictive models.
  • Unified data integration via custom APIs.
  • Demand forecasting with machine learning models.
  • Real-time analysis of A/B test results.

Streamlit in the AI Era

Synergy Between AI and Code

Recent advancements in AI have made code generation accessible even to non-engineers. The combination of Streamlit and AI has proven to be particularly effective.

1. Code Generation with GPT

Tools like ChatGPT and GitHub Copilot can generate application code from natural language prompts. The accuracy of AI-driven code generation has improved significantly. Streamlit's simple, single-file structure makes it an ideal target for this technology.

Example of code generation with ChatGPT

2. "No-Code with AI" Development

Using coding agents, developers can implement features by providing instructions in natural language. This workflow combines the speed of no-code development with the flexibility of a code-based approach.

  • Interactive Development: Build applications by giving instructions like "add this feature" or "modify this part."
  • Incremental Development: Start with small features and expand gradually.
  • Error Resolution: Use AI to diagnose and solve errors.

3. Access to the Latest AI Models

A code-based approach allows immediate access to the latest AI technologies. As new models are released with improved coding capabilities, they can be integrated into development workflows without delay.

Practical AI Applications

Code-based BI dashboards can leverage AI for both development and operational functions.

1. Natural Language Querying

Instead of relying on pre-written SQL queries, users can ask questions in natural language. An AI model can then generate the appropriate SQL query to retrieve the data.

# Conceptual structure of a natural language data analysis app
import streamlit as st
from langchain import OpenAI

st.title("Natural Language Data Analysis")
query = st.text_input("Enter your question")

if query:
    # AI generates SQL query
    llm = OpenAI()
    sql_query = llm(f"Convert question to SQL: {query}")
    
    # Display results
    result = execute_query(sql_query)
    st.dataframe(result)

2. Intelligent Report Generation

AI can automatically summarize analysis results and generate reports, allowing users to gain insights from data more quickly. This eliminates the need to pre-define report formats and rebuild dashboards for every change.

# AI-powered report generation
def generate_insights(data):
    insights = ai_analyzer.analyze(data)
    
    st.subheader("AI Analysis Results")
    for insight in insights:
        st.write(f"📊 {insight}")

Streamlit vs. Self-Service BI: A Comparison

Cost

AspectSelf-Service BIStreamlit
Initial CostHigh (license fees)Free (open source)
Recurring CostPer-user subscriptionsCloud infrastructure usage
Development EffortTime-consuming setupFast development after initial learning
Training CostTool-specific training requiredBasic Python knowledge is sufficient

Streamlit's Advantage: Significant cost savings, especially for small to medium-sized teams.

Operations

AspectSelf-Service BIStreamlit
Version ControlGUI-based, difficult to trackFull version control with Git
Environment ManagementManual sync of dev/test/prodReproducible environments via code (IaC)
Team CollaborationLimited concurrent editingParallel development with Git branches

Flexibility

AspectSelf-Service BIStreamlit
CustomizationLimited to vendor featuresUnlimited customization with Python
Data SourcesRestricted to supported connectorsConnect to any data source via APIs
AnalysisDependent on built-in functionsAccess to all Python data science libraries

AI Integration

AspectSelf-Service BIStreamlit
IntegrationLimited to vendor-provided AIUse any AI/ML library
Model AccessDelayed support for new modelsImmediate access to the latest models
DevelopmentLow compatibility with code-gen AIHigh compatibility with code-gen AI

Next Steps

To get started, you will need the following:

  1. Environment: A development environment like GitHub Codespaces.
  2. Python Basics: Familiarity with pandas DataFrames.
  3. Data: A clear idea of the data you want to visualize.
  4. AI Tools: Access to a code generation AI like ChatGPT.

The next chapter provides a step-by-step guide to setting up your environment.