Skip to content
This repository was archived by the owner on Apr 28, 2026. It is now read-only.

Commit 788bf54

Browse files
Tom GotsmanTom Gotsman
authored andcommitted
fixes
1 parent 2cc1469 commit 788bf54

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

blog/build-dashboard-python-without-javascript.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ image_zoom(src="https://d4bkhhmrfehmf.cloudfront.net/media/329d6193-80f9-494b-92
7272
```
7373

7474
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
7577
import reflex as rx
7678

7779
class DashboardState(rx.State):
@@ -80,10 +82,13 @@ class DashboardState(rx.State):
8082
{"month": "Feb", "amount": 15200},
8183
]
8284
selected_metric: str = "revenue"
85+
```
8386

8487
State variables become the source of truth. When `selected_metric` changes, every component using that value updates automatically without manual DOM manipulation.
8588

8689
Build the UI by composing components in a Python function. Each component accepts keyword arguments for styling and behavior.
90+
91+
```python
8792
def index():
8893
return rx.vstack(
8994
rx.heading("Revenue Dashboard"),
@@ -96,6 +101,7 @@ def index():
96101
data=DashboardState.revenue_data,
97102
),
98103
)
104+
```
99105

100106
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.
101107

@@ -104,6 +110,8 @@ Run `reflex run` and your dashboard appears at `localhost:3000`. Modify the data
104110
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.
105111

106112
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.
113+
114+
```python
107115
@rx.event(background=True)
108116
async def poll_api_continuously(self):
109117
async with self:
@@ -113,55 +121,72 @@ async def poll_api_continuously(self):
113121
async with self:
114122
self.current_value = fetch_latest_data()
115123
yield
124+
```
125+
116126
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.
117127

118128
Start a background task from any regular event handler by returning it as an event reference:
129+
130+
```python
119131
def start_monitoring(self):
120132
return DashboardState.poll_api_continuously
133+
```
121134

122135
Multiple users viewing the same dashboard see synchronized updates when shared state changes.
123136

124137
## Styling and Layout in Python
125138

126139
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.
140+
141+
```python
127142
rx.box(
128143
rx.text("Revenue: $45,200", font_size="24px", font_weight="bold"),
129144
padding="20px",
130145
border_radius="8px",
131146
box_shadow="lg",
132147
background="white",
133148
)
149+
```
134150

135151
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.
136152

137153
## Connecting to Data Sources and APIs
138154

139155
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.
156+
157+
```python
140158
import sqlalchemy
141159
from sqlalchemy import create_engine
142160

143161
class DashboardState(rx.State):
144162
metrics: list[dict] = []
145-
163+
146164
def load_data(self):
147165
engine = create_engine("postgresql://localhost/analytics")
148166
query = "SELECT date, revenue, users FROM metrics"
149167
self.metrics = pd.read_sql(query, engine).to_dict('records')
168+
```
150169

151170
API calls work the same way. Use `requests.get()` or any HTTP library, parse the response, and assign results to state variables.
171+
172+
```python
152173
def fetch_api_data(self):
153174
response = requests.get("https://api.example.com/metrics")
154175
self.api_metrics = response.json()
176+
```
155177

156178
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.
157179

158180
## Deployment Without Frontend Build Pipelines
159181

160182
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
161185
- name: Deploy to Reflex Cloud
162186
run: |
163187
pip install reflex
164188
reflex deploy
189+
```
165190
166191
[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.
167192

blog/django-vs-flask-vs-reflex-comparison.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ meta: [
1111
]
1212
faq: [
1313
{"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."},
1515
{"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."},
1616
{"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."},
1717
{"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
140140
| 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 | |
141141
| 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 | |
142142
| 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 | |
144144

145145
## Why Reflex Offers a Unique Approach for Python Teams
146146

blog/streamlit-vs-dash-python-dashboards.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ faq: [
2323
{"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."},
2424
{"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."},
2525
{"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."},
2727
{"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."}
2828
]
2929
---

0 commit comments

Comments
 (0)