├── .gitignore ├── LICENSE ├── README.md ├── dash_express ├── __init__.py ├── _app_shell.py ├── filters │ ├── __init__.py │ ├── autofilter.py │ └── filterfunc.py ├── kpi │ └── __init__.py ├── preview_chart.py └── version.py ├── docs ├── assets │ ├── css │ │ └── terminal.css │ ├── gifs │ │ ├── jupiter_preview.png │ │ └── min_app.gif │ └── js │ │ ├── custom.js │ │ └── terminal.js ├── authors.md ├── fundamentals │ ├── Add data.md │ ├── Create app.md │ ├── Visualization.md │ └── filters.md ├── index.md ├── installation.md ├── performance.md └── quickstart.md ├── mkdocs.yml ├── pyproject. toml ├── requirements.txt ├── requirements_docs.txt └── setup.py /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | __pycache__ 3 | .pytest_cache 4 | .venv 5 | build 6 | dash_express.egg-info 7 | dash_express.egg-info 8 | dist 9 | site 10 | test.py 11 | 12 | .cache -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Kirill Stepanov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fast analytical web application with DashExpress 2 | 3 | [Documentation](https://stpnvkirill.github.io/dash-express/) 4 | 5 | Build your next dashboard even faster with premade responsive UI and automatic callback-function. DashExpress is a wrapper over the Plotly Dash web framework, which allows you to simplify and speed up the creation of multi-page analytical applications based on data from pd.DataFrame. 6 | 7 | ```console 8 | pip install dash-express 9 | ``` 10 | 11 | Currently supported: Charts, KPI, Geographical Maps 12 | 13 | The key features are: 14 | 15 | * **High Performance**: Provided by built-in optimization methods of Dash callback functions. 16 | * **Fast to code**: Using a pre-configured UI and automatically generated callback functions. 17 | * **Based on Pandas**: A library familiar to all analysts. 18 | * **Used Mantine UI**: Pretty UI by Mantine React Library. 19 | * **Include Dark Theme**: Use a dark theme for all components (including graphs and maps) without any additional actions. 20 | 21 | 22 | ## Minimal full-featured dashboard 23 | 24 |  25 | 26 | The first step is to import the necessary libraries 27 | 28 | ```python 29 | import pandas as pd 30 | import plotly.graph_objects as go 31 | import dash_mantine_components as dmc 32 | 33 | from dash_express import DashExpress, Page 34 | ``` 35 | 36 | Next, you need to initialize an instance of the Dash Express application. 37 | 38 | ```python 39 | app = DashExpress( 40 | logo='DashExpress', # navbar logo, string or dict: {'dark':'path/to/darklogo.svg', 'light':...} 41 | cache=True, # flask_caching.Cache instance, dict or True (default: True) 42 | default_cache_timeout=3600, # flask_caching.Cache timeout in seconds (default: 3600) 43 | app_shell=..., # Appshell class for customization UI your app (default: BaseAppShell()) 44 | # And standart Plotly Dash param 45 | ) 46 | ``` 47 | 48 | The Dash Express object implements a Dash application with a pre-configured interface and automatic callback generation for quickly creating interactive multi-page web analytics applications. 49 | 50 | ## Page definition 51 | 52 | Each application page is a separate object, an instance of the `dash_express' class.Page`. The page contains the source data for analysis, graph creation functions and a list of filters. 53 | 54 | 55 | ```python 56 | page = Page( 57 | app=app, # DashExpress app 58 | url_path='/', # page url 59 | name='Owerview', # page name in navigation buttons 60 | get_df=get_df, # function for getting pd.DataFrame 61 | title='Owerview', # page title 62 | ) 63 | ``` 64 | 65 | ## Getting data 66 | 67 | The 'get_df` function contains the logic of getting data: 68 | 69 | ```python 70 | get_df = lambda: pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminder2007.csv') 71 | ``` 72 | 73 | ## Dashboard layout 74 | 75 | Next, you need to determine the layout of the dashboard. we recommend using dmc.Grid and dmc.SimpleGrid 76 | 77 | ```python 78 | page.layout = dmc.SimpleGrid( 79 | page.add_graph(h='100%',render_func=bar_func) 80 | ) 81 | ``` 82 | 83 | The render_func parameter of the page.add_graph method is a graph generation function based on data from a DataFrame 84 | 85 | ```python 86 | # The logic of drawing a graph 87 | def bar_func(df): 88 | pv = pd.pivot_table(df, index='continent', values='lifeExp').reset_index() 89 | fig = go.Figure([go.Bar(x=pv['continent'], y=pv['lifeExp'])]) 90 | return fig 91 | ``` 92 | 93 | The last action is to add filters, which is done by simply calling the page.add_filter method and specifying the filtering column. 94 | 95 | ```python 96 | page.add_autofilter('continent', multi=True) 97 | page.add_autofilter('country', multi=True) 98 | page.add_autofilter('lifeExp', multi=True) 99 | ``` 100 | 101 | ## App run 102 | 103 | These actions are enough to create a fully functional dashboard, so you can run the application. 104 | 105 | 106 | ```python 107 | app.run() 108 | ``` 109 | 110 | ## Full code of the minimal application 111 | 112 | ```python 113 | import pandas as pd 114 | import plotly.graph_objects as go 115 | import dash_mantine_components as dmc 116 | 117 | from dash_express import DashExpress, Page 118 | 119 | 120 | # Incorporate data 121 | get_df = lambda: pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/gapminder2007.csv') 122 | 123 | # Initialize the app 124 | app = DashExpress(logo='DashExpress') 125 | 126 | # Initialize the Page 127 | page = Page( 128 | app=app, # DashExpress app 129 | url_path='/', # page url 130 | name='Owerview', # page name in navigation buttons 131 | get_df=get_df, # function for getting pd.DataFrame 132 | title='Owerview', # page title 133 | ) 134 | 135 | # The logic of drawing a graph 136 | def bar_func(df): 137 | pv = pd.pivot_table(df, index='continent', values='lifeExp').reset_index() 138 | fig = go.Figure([go.Bar(x=pv['continent'], y=pv['lifeExp'])]) 139 | return fig 140 | 141 | # Dashboard layout 142 | page.layout = dmc.SimpleGrid( 143 | page.add_graph(h='calc(100vh - 138px)',render_func=bar_func) 144 | ) 145 | 146 | # By which columns to filter 147 | page.add_autofilter('continent', multi=True) 148 | page.add_autofilter('country', multi=True) 149 | page.add_autofilter('lifeExp', multi=True) 150 | 151 | app.run(debug=True) 152 | ``` 153 | 154 | ## Requirements 155 | 156 | Python 3.7+ 157 | 158 | DashExpress stands on the shoulders of giants: 159 | 160 | * Plotly Dash for the web parts. 161 | * Pandas DataFrame for the data store & compute measure. 162 | * Dash Mantine Components for the create pretty UI 163 | * Dash Leaflet for the create maps 164 | 165 | ## License 166 | 167 | This project is licensed under the terms of the MIT license. -------------------------------------------------------------------------------- /dash_express/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | import uuid 4 | import random 5 | import orjson 6 | 7 | import numpy as np 8 | import pandas as pd 9 | import dash_leaflet as dl 10 | import plotly.graph_objects as go 11 | import dash_mantine_components as dmc 12 | 13 | 14 | from .version import V 15 | from .kpi import KPI, FastKPI 16 | from .filters import autofilter 17 | from flask_caching import Cache 18 | from dash_iconify import DashIconify 19 | from .preview_chart import _render_wrapper 20 | from dash.exceptions import PreventUpdate 21 | from dash._jupyter import JupyterDisplayMode 22 | from ._app_shell import BaseAppShell, AsideAppShell 23 | from dash import Dash, Output, Input, State, ALL, dcc, html, Patch, MATCH 24 | 25 | 26 | _default_index = """ 27 | 28 |
29 | {%metas%} 30 |