A modular Dash application for analyzing data through SQL queries with various visualization and analysis tools.
- SQL query execution with parameter support
- Dynamic report generation with custom reporting capabilities
- YData profiling for detailed data analysis
- VizroAI visualization using natural language
- Custom SQL query support
- Automatic date picker for date parameters
- Flexible parameter pattern matching
- Clone the repository
- Create and activate a virtual environment:
python -m venv venv
- Install dependencies:
pip install -r requirements.txt
- dash
- pandas
- ydata-profiling
- vizro-ai
- python-dotenv
- Create your source module following the structure below
- Run the application using one of these methods:
Using the batch file (Windows):
# Run with default source
run.bat
# Run with specific source
run.bat your_source_name
Using Python directly:
python app.py [source_module_name]
If no source module is specified, it defaults to 'example'.
your_source/
├── connection.py # Database connection and query configuration
├── queries/ # SQL query files
│ └── your_query.sql
└── reports/ # Custom report modules
└── your_query.py # (same name as SQL file without .sql extension)
import re
# Required: Pattern for extracting parameters from SQL queries
# Default pattern matches: column_name = ?
# Extended pattern matches: column_name > ?, column_name < ?, etc.
QUERY_PARAM_PATTERN = re.compile(r'(\w+)\s*(?:[=><!]+)\s*\?')
# Required: Whether to replace parameters in SQL query
QUERY_PARAM_REPLACE_MODE = False
# Required: Database connection function
def get_connection():
# Implement your database connection logic
return your_connection
- Place your SQL files in
your_source/queries/
- Use parameterized queries with the format matching your
QUERY_PARAM_PATTERN
- Parameters containing 'date' in their name will automatically get a date picker
Example:
-- your_source/queries/sales_report.sql
SELECT * FROM sales
WHERE revenue > ?
AND transaction_date > ?;
Create custom report modules in your_source/reports/
to generate specialized reports for specific queries.
- Create a Python file with the same name as your SQL file (without .sql extension)
- Implement a
create_report
function that takes a pandas DataFrame as input
Example:
# your_source/reports/sales_report.py
def create_report(df):
"""
Create a custom report from the query results.
Args:
df (pd.DataFrame): The query results as a DataFrame
Returns:
dict: A dictionary that will be unpacked into Dash components
"""
return {
'summary': df.describe().to_dict(),
'custom_stats': {
'total_revenue': df['revenue'].sum(),
'average_transaction': df['revenue'].mean()
}
}
-
When "Generate Report" is clicked, the system:
- Takes the current query name (e.g., "sales_report.sql")
- Looks for a matching report module (e.g., "sales_report.py")
- Tries to use its
create_report
function
-
Fallback behavior:
- If no matching report module exists → uses
df.describe()
- If module exists but no
create_report
function → usesdf.describe()
- If any error occurs during report generation → shows error message
- If no matching report module exists → uses
-
Report Data Format:
- Return a dictionary from
create_report
- The dictionary will be unpacked into Dash components
- Nested dictionaries become nested divs
- Lists become bullet points
- DataFrames/Series are converted to tables
- Return a dictionary from
- YData Profiling: Generate detailed data profiling reports
- VizroAI: Create visualizations using natural language descriptions
- Custom SQL: Run ad-hoc SQL queries directly
- Select a query from the dropdown
- Fill in any required parameters
- Click "Run Query" to execute
- Use the various tools in the sidebar to analyze the results:
- Generate Report: Custom or basic statistics
- YData Profiling: Detailed data analysis
- VizroAI: AI-powered visualizations
To add a new feature:
- Update the relevant module
- Add any new dependencies to requirements.txt
- Update documentation if necessary
- Fork the repository
- Create a feature branch
- Submit a pull request
MIT