You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 28, 2026. It is now read-only.
Create a new file called `dashboard.py` and start with state. Your dashboard needs data and variables that track user interactions, so define them as a Python class.
75
+
76
+
```python
75
77
import reflex as rx
76
78
77
79
classDashboardState(rx.State):
@@ -80,10 +82,13 @@ class DashboardState(rx.State):
80
82
{"month": "Feb", "amount": 15200},
81
83
]
82
84
selected_metric: str="revenue"
85
+
```
83
86
84
87
State variables become the source of truth. When `selected_metric` changes, every component using that value updates automatically without manual DOM manipulation.
85
88
86
89
Build the UI by composing components in a Python function. Each component accepts keyword arguments for styling and behavior.
90
+
91
+
```python
87
92
defindex():
88
93
return rx.vstack(
89
94
rx.heading("Revenue Dashboard"),
@@ -96,6 +101,7 @@ def index():
96
101
data=DashboardState.revenue_data,
97
102
),
98
103
)
104
+
```
99
105
100
106
Run `reflex run` and your dashboard appears at `localhost:3000`. Modify the data in your state class, save the file, and watch the charts update instantly.
101
107
@@ -104,6 +110,8 @@ Run `reflex run` and your dashboard appears at `localhost:3000`. Modify the data
104
110
Real-time dashboards update when data changes. In JavaScript frameworks, you'd attach event listeners, manage WebSocket connections, and manually update DOM elements. Reflex handles this through background tasks and Python's async patterns.
105
111
106
112
Background tasks run independently without blocking the UI. Decorate an async method with `@rx.event(background=True)` and wrap state mutations in `async with self:` blocks. Each mutation triggers a UI update with the current state, so your dashboard refreshes in real time while the task continues running.
The dashboard shows each update as the loop executes. Users see values change every second without you having to write WebSocket handlers or manage connection state.
117
127
118
128
Start a background task from any regular event handler by returning it as an event reference:
129
+
130
+
```python
119
131
defstart_monitoring(self):
120
132
return DashboardState.poll_api_continuously
133
+
```
121
134
122
135
Multiple users viewing the same dashboard see synchronized updates when shared state changes.
123
136
124
137
## Styling and Layout in Python
125
138
126
139
Every component accepts styling through keyword arguments. Pass `color`, `padding`, `margin`, `font_size`, or any CSS property as a Python parameter. Want a card with rounded corners and shadow? Write it as function arguments.
Layout comes from component nesting. Stack components vertically with `rx.vstack`, arrange horizontally with `rx.hstack`, or create grid layouts with `rx.grid`. Reflex includes a theming system for consistent styling across your dashboard. Responsive design works through the same keyword arguments. Pass a list of values for different screen sizes: `width=["100%", "50%", "33%"]` displays full-width on mobile, half-width on tablet, and third-width on desktop.
136
152
137
153
## Connecting to Data Sources and APIs
138
154
139
155
Dashboards are only as good as the data they visualize. Your dashboard can pull data from databases, APIs, and external services. Import the Python libraries you already use: `requests` for REST APIs, `pandas` for data manipulation, `SQLAlchemy` for database connections, `psycopg2` for PostgreSQL. Then, connect to a database directly in your state class. Finally, query data in event handlers using the same SQL patterns you write for data analysis.
Your entire PyPI ecosystem works inside dashboards. Need authentication? Use the same auth library you use in backend services. Parse CSV files? Import pandas. Connect to Snowflake or MongoDB using their Python SDKs.
157
179
158
180
## Deployment Without Frontend Build Pipelines
159
181
160
182
Reflex deploys with `reflex deploy`. One command packages your Python application and provisions infrastructure. No webpack configuration, no build scripts, no compiled frontend assets to manage. The deployment process mirrors deploying Flask or Django applications: your Python code goes directly to production without compilation steps. CI/CD pipelines run the same command in GitHub Actions, GitLab CI, or custom automation.
183
+
184
+
```yaml
161
185
- name: Deploy to Reflex Cloud
162
186
run: |
163
187
pip install reflex
164
188
reflex deploy
189
+
```
165
190
166
191
[Reflex Cloud handles scaling and infrastructure](https://reflex.dev/hosting/) automatically. Organizations requiring on-premises deployment can run Reflex in their own environments using the same Python codebase.
Copy file name to clipboardExpand all lines: blog/django-vs-flask-vs-reflex-comparison.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ meta: [
11
11
]
12
12
faq: [
13
13
{"question": "How does Reflex differ from Django and Flask for full stack development?", "answer": "Django and Flask both require JavaScript frameworks like React or Vue for the frontend, splitting your team between Python backend developers and JavaScript frontend specialists. Reflex lets you write both frontend and backend in pure Python, compiling Python code into a React application automatically without touching JavaScript."},
14
-
{"question": "Can I deploy Reflex applications in my own infrastructure?", "answer": "Yes, Reflex supports on-premises deployment and VPC options for enterprise security requirements. You can run Reflex Build in your own environment while maintaining full control over data and code, meeting compliance requirements that cloud-only tools cannot satisfy."},
14
+
{"question": "Can I deploy Reflex applications in my own infrastructure?", "answer": "Yes, Reflex supports on-premises deployment and VPC options for enterprise security requirements. You can run Reflex's AI App Builder in your own environment while maintaining full control over data and code, meeting compliance requirements that cloud-only tools cannot satisfy."},
15
15
{"question": "What's the learning curve like for Python developers new to web development?", "answer": "Python developers can start building full stack applications immediately without learning React, state management libraries, or frontend build tools. You write Python classes for state and Python functions for UI, skipping the JavaScript barrier entirely while Django requires learning ORM, middleware, and template systems first."},
16
16
{"question": "How does Reflex handle production performance compared to Django or Flask?", "answer": "Reflex compiles Python into standard React for the frontend, delivering production React performance with Python backend response times comparable to Flask APIs. The compilation happens during development, so production applications run as optimized React frontends with Python backends."},
17
17
{"question": "When should I choose Reflex over Django for my project?", "answer": "Choose Reflex when you need interactive dashboards, real-time data visualization, or dynamic user interfaces without hiring separate frontend specialists. If your team already uses Python for data science, machine learning, or backend services and wants to maintain a single language across your entire application stack, Reflex removes the coordination overhead of splitting your codebase across languages."}
@@ -140,7 +140,7 @@ Reflex, though, deploys with `reflex deploy`. This command pushes your applicati
140
140
| Frontend Development | Server-side templates with Jinja2 or separate JavaScript frontend using Django REST Framework for API serialization | No opinion on frontend, requiring choice between server-side Jinja2 templates or building separate JavaScript frontend | Pure Python frontend that compiles to React automatically, allowing developers to write UI components and state management entirely in Python ||
141
141
| Deployment Complexity | Requires WSGI server setup with Gunicorn, Nginx reverse proxy configuration, manual static file management, and database migration handling | Similar WSGI deployment requirements with lighter resource needs but same manual configuration for web server, static assets, and database connections | Single command deployment with 'reflex deploy' that handles infrastructure provisioning, multi-region scaling, and monitoring automatically ||
142
142
| Built-in Features | ORM with automatic migrations, admin interface, user authentication, form validation, security protections against SQL injection and XSS | Werkzeug for WSGI utilities and Jinja2 for templating only, requiring external packages for database, authentication, and form handling | 60+ built-in components, state management through Python classes, event handlers, automatic UI updates, and integrated frontend-backend architecture ||
143
-
| Ideal Use Cases | Content management systems, data-intensive applications with complex relational queries, best suited for teams already comfortable managing separate Python backends and Javascript frontends for any interactive or user-facing features | Microservices architectures, API-first projects for mobile apps or SPAs, projects where teams want granular control over dependency selection | Fortune 500 teams and compliance-focused industries (finance, healthcare, government) building enterprise-grade internal tools, interactive dashboards, real-time data visualization, LLM chat apps, and AI-powered workflows entirely in Python, eliminating frontend specialist headcount, maintaining audit-ready codebases, and deploying to on-premises or VPC infrastructure for full data sovereignty ||
143
+
| Ideal Use Cases | Content management systems, data-intensive applications with complex relational queries, best suited for teams already comfortable managing separate Python backends and JavaScript frontends for any interactive or user-facing features | Microservices architectures, API-first projects for mobile apps or SPAs, projects where teams want granular control over dependency selection | Fortune 500 teams and compliance-focused industries (finance, healthcare, government) building enterprise-grade internal tools, interactive dashboards, real-time data visualization, LLM chat apps, and AI-powered workflows entirely in Python, eliminating frontend specialist headcount, maintaining audit-ready codebases, and deploying to on-premises or VPC infrastructure for full data sovereignty ||
144
144
145
145
## Why Reflex Offers a Unique Approach for Python Teams
Copy file name to clipboardExpand all lines: blog/streamlit-vs-dash-python-dashboards.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@ faq: [
23
23
{"question": "What is Reflex's state management approach and how is it different?", "answer": "Reflex uses Python class-based state management where you define application state in classes and write event handlers as methods. The framework automatically tracks dependencies and updates only affected components through WebSocket synchronization, avoiding both Streamlit's full script reruns and Dash's manual callback wiring."},
24
24
{"question": "Why do data science teams struggle when moving Streamlit or Dash prototypes to production?", "answer": "Both frameworks handle the UI layer well for demos but lack authentication, RBAC, secure deployment, and production features that business applications need. Teams end up spending weeks building session management, user databases, and infrastructure that isn't included in the framework. Reflex includes built-in authentication with Clerk, Google Auth, Azure, and OpenID Connect providers, plus RBAC and one-command deployment, so production requirements are covered from day one."},
25
25
{"question": "How much code reduction does Reflex provide compared to Dash?", "answer": "Teams building equivalent dashboards in Reflex report approximately 50% less code compared to Dash implementations. The class-based structure and automatic dependency tracking in Reflex eliminate the callback wiring ceremony that accumulates in Dash applications as connected components multiply."},
26
-
{"question": "What types of organizations use Reflex for production applications?", "answer": "Finance teams run trading dashboards, healthcare organizations manage patient data, and government agencies deploy internal tools using Reflex. The framework is trusted by 30% of Fortune 500 companies for building production-grade web applications entirely in Python."},
26
+
{"question": "What types of organizations use Reflex for production applications?", "answer": "Finance teams run trading dashboards, healthcare organizations manage patient data, and government agencies deploy internal tools using Reflex. The framework is trusted by 40% of Fortune 500 companies for building production-grade web applications entirely in Python."},
27
27
{"question": "Does Dash support multi-page applications out of the box?", "answer": "No, Dash requires extra configuration beyond the core framework to support multi-page applications. This adds another layer of setup complexity on top of the callback wiring and layout construction that Dash already requires. Reflex includes multi-page support with a built-in file-based routing system, dynamic routes, and shared state across pages without additional configuration."}
0 commit comments