streamlit-react-components 0.1.1__tar.gz → 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {streamlit_react_components-0.1.1/src/streamlit_react_components.egg-info → streamlit_react_components-1.0.0}/PKG-INFO +199 -22
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/README.md +198 -21
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/pyproject.toml +1 -1
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/src/streamlit_react_components/__init__.py +2 -0
- streamlit_react_components-1.0.0/src/streamlit_react_components/_frontend/index.js +3920 -0
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/src/streamlit_react_components/common/__init__.py +2 -0
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/src/streamlit_react_components/common/button_group.py +13 -1
- streamlit_react_components-1.0.0/src/streamlit_react_components/common/plotly_chart.py +216 -0
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/src/streamlit_react_components/common/section_header.py +33 -3
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/src/streamlit_react_components/common/stat_card.py +10 -1
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/src/streamlit_react_components/form/form_slider.py +12 -1
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0/src/streamlit_react_components.egg-info}/PKG-INFO +199 -22
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/src/streamlit_react_components.egg-info/SOURCES.txt +1 -0
- streamlit_react_components-0.1.1/src/streamlit_react_components/_frontend/index.js +0 -63
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/MANIFEST.in +0 -0
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/setup.cfg +0 -0
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/src/streamlit_react_components/_frontend/index.css +0 -0
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/src/streamlit_react_components/_frontend/index.html +0 -0
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/src/streamlit_react_components/common/chart_legend.py +0 -0
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/src/streamlit_react_components/common/data_table.py +0 -0
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/src/streamlit_react_components/common/metric_row.py +0 -0
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/src/streamlit_react_components/common/panel.py +0 -0
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/src/streamlit_react_components/common/step_indicator.py +0 -0
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/src/streamlit_react_components/form/__init__.py +0 -0
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/src/streamlit_react_components/form/checkbox_group.py +0 -0
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/src/streamlit_react_components/form/form_select.py +0 -0
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/src/streamlit_react_components.egg-info/dependency_links.txt +0 -0
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/src/streamlit_react_components.egg-info/requires.txt +0 -0
- {streamlit_react_components-0.1.1 → streamlit_react_components-1.0.0}/src/streamlit_react_components.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: streamlit-react-components
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 1.0.0
|
|
4
4
|
Summary: Reusable React-based Streamlit components with Tailwind CSS styling
|
|
5
5
|
License: MIT
|
|
6
6
|
Project-URL: Homepage, https://github.com/your-org/streamlit-react-components
|
|
@@ -19,7 +19,7 @@ Requires-Dist: streamlit>=1.24.0
|
|
|
19
19
|
|
|
20
20
|
# Streamlit React Components
|
|
21
21
|
|
|
22
|
-
A collection of
|
|
22
|
+
A collection of 12 reusable React-based Streamlit components with Tailwind CSS styling. All components support custom inline styles and Tailwind class names.
|
|
23
23
|
|
|
24
24
|
## Installation
|
|
25
25
|
|
|
@@ -34,7 +34,7 @@ import streamlit as st
|
|
|
34
34
|
from streamlit_react_components import (
|
|
35
35
|
panel, section_header, stat_card, metric_row,
|
|
36
36
|
data_table, step_indicator, button_group, chart_legend,
|
|
37
|
-
form_select, form_slider, checkbox_group
|
|
37
|
+
plotly_chart, form_select, form_slider, checkbox_group
|
|
38
38
|
)
|
|
39
39
|
```
|
|
40
40
|
|
|
@@ -123,11 +123,15 @@ actions = [
|
|
|
123
123
|
| `id` | `str` | Unique identifier (returned on click) |
|
|
124
124
|
| `label` | `str` | Button text (optional) |
|
|
125
125
|
| `icon` | `str` | Emoji/icon (optional) |
|
|
126
|
-
| `color` | `str` | `"blue"`, `"green"`, `"red"`, `"yellow"`, `"purple"` |
|
|
126
|
+
| `color` | `str` | Preset (`"blue"`, `"green"`, `"red"`, `"yellow"`, `"purple"`, `"slate"`) or hex (e.g., `"#94a3b8"`) |
|
|
127
|
+
| `style` | `dict` | Inline CSS styles for this button (optional) |
|
|
128
|
+
| `className` | `str` | Tailwind classes for this button (optional) |
|
|
129
|
+
| `href` | `str` | URL for link actions. External URLs (http/https) open in new tab (optional) |
|
|
127
130
|
|
|
128
131
|
#### Example
|
|
129
132
|
|
|
130
133
|
```python
|
|
134
|
+
# Using preset colors
|
|
131
135
|
clicked = section_header(
|
|
132
136
|
title="Executive Summary",
|
|
133
137
|
icon="📊",
|
|
@@ -137,8 +141,31 @@ clicked = section_header(
|
|
|
137
141
|
]
|
|
138
142
|
)
|
|
139
143
|
|
|
140
|
-
|
|
141
|
-
|
|
144
|
+
# Using hex colors and custom styling
|
|
145
|
+
clicked = section_header(
|
|
146
|
+
title="Custom Actions",
|
|
147
|
+
actions=[
|
|
148
|
+
{"id": "custom", "label": "Custom", "color": "#ff5733"},
|
|
149
|
+
{"id": "styled", "label": "Styled", "style": {"padding": "12px", "borderRadius": "20px"}}
|
|
150
|
+
]
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
# External link (opens in new tab)
|
|
154
|
+
section_header(
|
|
155
|
+
title="Resources",
|
|
156
|
+
actions=[
|
|
157
|
+
{"id": "docs", "label": "Documentation", "href": "https://docs.example.com", "icon": "📚"},
|
|
158
|
+
{"id": "github", "label": "GitHub", "href": "https://github.com", "color": "slate"}
|
|
159
|
+
]
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
# Internal page navigation
|
|
163
|
+
clicked = section_header(
|
|
164
|
+
title="Settings",
|
|
165
|
+
actions=[{"id": "home", "label": "Home", "icon": "🏠"}]
|
|
166
|
+
)
|
|
167
|
+
if clicked == "home":
|
|
168
|
+
st.switch_page("pages/home.py")
|
|
142
169
|
```
|
|
143
170
|
|
|
144
171
|
---
|
|
@@ -161,13 +188,17 @@ stat_card(
|
|
|
161
188
|
|
|
162
189
|
#### Colors
|
|
163
190
|
|
|
164
|
-
|
|
165
|
-
|
|
191
|
+
Supports preset color names or hex values:
|
|
192
|
+
|
|
193
|
+
| Preset | Border | Text |
|
|
194
|
+
|--------|--------|------|
|
|
166
195
|
| `"blue"` | `border-blue-500` | `text-blue-400` |
|
|
167
196
|
| `"green"` | `border-green-500` | `text-green-400` |
|
|
168
197
|
| `"red"` | `border-red-500` | `text-red-400` |
|
|
169
198
|
| `"yellow"` | `border-yellow-500` | `text-yellow-400` |
|
|
170
199
|
| `"purple"` | `border-purple-500` | `text-purple-400` |
|
|
200
|
+
| `"slate"` | `border-slate-500` | `text-slate-400` |
|
|
201
|
+
| `"#xxxxxx"` | Custom hex color | Custom hex color |
|
|
171
202
|
|
|
172
203
|
#### Example
|
|
173
204
|
|
|
@@ -182,6 +213,9 @@ with col3:
|
|
|
182
213
|
stat_card(label="Below (Underutil)", value="1", color="yellow")
|
|
183
214
|
with col4:
|
|
184
215
|
stat_card(label="Avg OEE", value="78.4%", color="blue")
|
|
216
|
+
|
|
217
|
+
# Using hex color
|
|
218
|
+
stat_card(label="Custom Color", value="42", color="#ff5733")
|
|
185
219
|
```
|
|
186
220
|
|
|
187
221
|
---
|
|
@@ -364,12 +398,15 @@ buttons = [
|
|
|
364
398
|
| `id` | `str` | Unique identifier (returned on click) |
|
|
365
399
|
| `label` | `str` | Button text (optional) |
|
|
366
400
|
| `icon` | `str` | Emoji/icon (optional) |
|
|
367
|
-
| `color` | `str` | `"blue"`, `"green"`, `"red"`, `"yellow"`, `"purple"`, `"slate"` |
|
|
401
|
+
| `color` | `str` | Preset (`"blue"`, `"green"`, `"red"`, `"yellow"`, `"purple"`, `"slate"`) or hex (e.g., `"#94a3b8"`) |
|
|
368
402
|
| `disabled` | `bool` | Disable the button |
|
|
403
|
+
| `style` | `dict` | Inline CSS styles for this button (optional) |
|
|
404
|
+
| `className` | `str` | Tailwind classes for this button (optional) |
|
|
369
405
|
|
|
370
406
|
#### Example
|
|
371
407
|
|
|
372
408
|
```python
|
|
409
|
+
# Using preset colors
|
|
373
410
|
clicked = button_group(
|
|
374
411
|
buttons=[
|
|
375
412
|
{"id": "view", "icon": "👁️", "label": "View"},
|
|
@@ -378,6 +415,14 @@ clicked = button_group(
|
|
|
378
415
|
]
|
|
379
416
|
)
|
|
380
417
|
|
|
418
|
+
# Using hex colors and custom styling
|
|
419
|
+
clicked = button_group(
|
|
420
|
+
buttons=[
|
|
421
|
+
{"id": "custom", "icon": "🎨", "color": "#ff5733"},
|
|
422
|
+
{"id": "styled", "label": "Styled", "style": {"padding": "12px"}}
|
|
423
|
+
]
|
|
424
|
+
)
|
|
425
|
+
|
|
381
426
|
if clicked == "delete":
|
|
382
427
|
st.warning("Delete clicked!")
|
|
383
428
|
```
|
|
@@ -427,7 +472,140 @@ chart_legend(
|
|
|
427
472
|
|
|
428
473
|
---
|
|
429
474
|
|
|
430
|
-
### 9.
|
|
475
|
+
### 9. Plotly Chart
|
|
476
|
+
|
|
477
|
+
Render Plotly charts with full interactivity and event callbacks.
|
|
478
|
+
|
|
479
|
+
```python
|
|
480
|
+
plotly_chart(
|
|
481
|
+
# Data source (one required)
|
|
482
|
+
figure: Any = None, # Plotly figure or dict
|
|
483
|
+
data: DataFrame = None, # pandas DataFrame
|
|
484
|
+
|
|
485
|
+
# DataFrame options (when using data=)
|
|
486
|
+
x: str = None, # Column name for x-axis
|
|
487
|
+
y: str | list = None, # Column name(s) for y-axis
|
|
488
|
+
color: str = None, # Column name for color grouping
|
|
489
|
+
chart_type: str = "line", # "line", "bar", "scatter", "area", "pie", "histogram"
|
|
490
|
+
title: str = None, # Chart title
|
|
491
|
+
|
|
492
|
+
# Plotly config
|
|
493
|
+
config: dict = None, # Plotly config options
|
|
494
|
+
|
|
495
|
+
# Event callbacks
|
|
496
|
+
on_click: bool = False, # Enable click events
|
|
497
|
+
on_select: bool = False, # Enable selection events
|
|
498
|
+
on_hover: bool = False, # Enable hover events
|
|
499
|
+
on_relayout: bool = False, # Enable zoom/pan events
|
|
500
|
+
|
|
501
|
+
# Styling
|
|
502
|
+
style: dict = None,
|
|
503
|
+
class_name: str = "",
|
|
504
|
+
key: str = None
|
|
505
|
+
) -> dict | None # Returns event dict or None
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
#### Using Plotly Figure
|
|
509
|
+
|
|
510
|
+
```python
|
|
511
|
+
import plotly.graph_objects as go
|
|
512
|
+
|
|
513
|
+
fig = go.Figure(
|
|
514
|
+
data=[
|
|
515
|
+
go.Scatter(x=[1,2,3,4,5], y=[10,15,13,17,20], mode='lines+markers', name='Sales'),
|
|
516
|
+
go.Bar(x=[1,2,3,4,5], y=[5,8,6,9,12], name='Orders')
|
|
517
|
+
],
|
|
518
|
+
layout=go.Layout(title='Sales Dashboard')
|
|
519
|
+
)
|
|
520
|
+
|
|
521
|
+
event = plotly_chart(
|
|
522
|
+
figure=fig,
|
|
523
|
+
on_click=True,
|
|
524
|
+
on_select=True,
|
|
525
|
+
style={"height": "400px"}
|
|
526
|
+
)
|
|
527
|
+
|
|
528
|
+
if event and event['type'] == 'click':
|
|
529
|
+
st.write(f"Clicked: {event['points']}")
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
#### Using DataFrame
|
|
533
|
+
|
|
534
|
+
```python
|
|
535
|
+
import pandas as pd
|
|
536
|
+
|
|
537
|
+
df = pd.DataFrame({
|
|
538
|
+
'month': ['Jan', 'Feb', 'Mar', 'Apr'],
|
|
539
|
+
'sales': [100, 150, 120, 180],
|
|
540
|
+
'orders': [50, 75, 60, 90]
|
|
541
|
+
})
|
|
542
|
+
|
|
543
|
+
# Simple line chart
|
|
544
|
+
event = plotly_chart(
|
|
545
|
+
data=df,
|
|
546
|
+
x='month',
|
|
547
|
+
y='sales',
|
|
548
|
+
chart_type='line',
|
|
549
|
+
title='Monthly Sales'
|
|
550
|
+
)
|
|
551
|
+
|
|
552
|
+
# Multiple y columns as bar chart
|
|
553
|
+
event = plotly_chart(
|
|
554
|
+
data=df,
|
|
555
|
+
x='month',
|
|
556
|
+
y=['sales', 'orders'],
|
|
557
|
+
chart_type='bar',
|
|
558
|
+
title='Sales vs Orders'
|
|
559
|
+
)
|
|
560
|
+
|
|
561
|
+
# Scatter with color grouping
|
|
562
|
+
event = plotly_chart(
|
|
563
|
+
data=df,
|
|
564
|
+
x='sales',
|
|
565
|
+
y='orders',
|
|
566
|
+
color='month',
|
|
567
|
+
chart_type='scatter'
|
|
568
|
+
)
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
#### Chart Types (DataFrame mode)
|
|
572
|
+
|
|
573
|
+
| Type | Description |
|
|
574
|
+
|------|-------------|
|
|
575
|
+
| `"line"` | Line chart with connected points |
|
|
576
|
+
| `"scatter"` | Scatter plot with markers only |
|
|
577
|
+
| `"bar"` | Vertical bar chart |
|
|
578
|
+
| `"area"` | Area chart (filled line) |
|
|
579
|
+
| `"pie"` | Pie chart (x=labels, y=values) |
|
|
580
|
+
| `"histogram"` | Histogram of x values |
|
|
581
|
+
|
|
582
|
+
#### Event Types
|
|
583
|
+
|
|
584
|
+
| Event | When Triggered | Data Returned |
|
|
585
|
+
|-------|----------------|---------------|
|
|
586
|
+
| `click` | User clicks a data point | `{type: 'click', points: [...]}` |
|
|
587
|
+
| `select` | User box/lasso selects points | `{type: 'select', points: [...]}` |
|
|
588
|
+
| `hover` | User hovers over a point | `{type: 'hover', points: [...]}` |
|
|
589
|
+
| `relayout` | User zooms/pans the chart | `{type: 'relayout', relayout: {...}}` |
|
|
590
|
+
|
|
591
|
+
#### Point Data Structure
|
|
592
|
+
|
|
593
|
+
Each point in the `points` array contains:
|
|
594
|
+
|
|
595
|
+
```python
|
|
596
|
+
{
|
|
597
|
+
"curveNumber": 0, # Index of the trace
|
|
598
|
+
"pointNumber": 2, # Index of the point in the trace
|
|
599
|
+
"pointIndex": 2, # Same as pointNumber
|
|
600
|
+
"x": "Mar", # X value
|
|
601
|
+
"y": 120, # Y value
|
|
602
|
+
"customdata": None # Custom data if provided
|
|
603
|
+
}
|
|
604
|
+
```
|
|
605
|
+
|
|
606
|
+
---
|
|
607
|
+
|
|
608
|
+
### 10. Form Select
|
|
431
609
|
|
|
432
610
|
A styled dropdown select input.
|
|
433
611
|
|
|
@@ -490,7 +668,7 @@ scenario = form_select(
|
|
|
490
668
|
|
|
491
669
|
---
|
|
492
670
|
|
|
493
|
-
###
|
|
671
|
+
### 11. Form Slider
|
|
494
672
|
|
|
495
673
|
A styled range slider input.
|
|
496
674
|
|
|
@@ -502,7 +680,7 @@ form_slider(
|
|
|
502
680
|
max_val: float, # Maximum value
|
|
503
681
|
step: float = 1, # Step increment
|
|
504
682
|
unit: str = "", # Unit suffix (e.g., "%", "hrs")
|
|
505
|
-
color: str = "blue", #
|
|
683
|
+
color: str = "blue", # Preset or hex color (e.g., "#94a3b8")
|
|
506
684
|
style: dict = None,
|
|
507
685
|
class_name: str = "",
|
|
508
686
|
key: str = None
|
|
@@ -512,7 +690,7 @@ form_slider(
|
|
|
512
690
|
#### Example
|
|
513
691
|
|
|
514
692
|
```python
|
|
515
|
-
# Percentage slider
|
|
693
|
+
# Percentage slider with preset color
|
|
516
694
|
threshold = form_slider(
|
|
517
695
|
label="Upper Threshold",
|
|
518
696
|
value=90,
|
|
@@ -533,20 +711,19 @@ hold_time = form_slider(
|
|
|
533
711
|
color="blue"
|
|
534
712
|
)
|
|
535
713
|
|
|
536
|
-
#
|
|
537
|
-
|
|
538
|
-
label="
|
|
539
|
-
value=
|
|
540
|
-
min_val=
|
|
541
|
-
max_val=
|
|
542
|
-
|
|
543
|
-
color="green"
|
|
714
|
+
# Slider with hex color
|
|
715
|
+
custom_slider = form_slider(
|
|
716
|
+
label="Custom Color",
|
|
717
|
+
value=50,
|
|
718
|
+
min_val=0,
|
|
719
|
+
max_val=100,
|
|
720
|
+
color="#ff5733"
|
|
544
721
|
)
|
|
545
722
|
```
|
|
546
723
|
|
|
547
724
|
---
|
|
548
725
|
|
|
549
|
-
###
|
|
726
|
+
### 12. Checkbox Group
|
|
550
727
|
|
|
551
728
|
A group of checkboxes.
|
|
552
729
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Streamlit React Components
|
|
2
2
|
|
|
3
|
-
A collection of
|
|
3
|
+
A collection of 12 reusable React-based Streamlit components with Tailwind CSS styling. All components support custom inline styles and Tailwind class names.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -15,7 +15,7 @@ import streamlit as st
|
|
|
15
15
|
from streamlit_react_components import (
|
|
16
16
|
panel, section_header, stat_card, metric_row,
|
|
17
17
|
data_table, step_indicator, button_group, chart_legend,
|
|
18
|
-
form_select, form_slider, checkbox_group
|
|
18
|
+
plotly_chart, form_select, form_slider, checkbox_group
|
|
19
19
|
)
|
|
20
20
|
```
|
|
21
21
|
|
|
@@ -104,11 +104,15 @@ actions = [
|
|
|
104
104
|
| `id` | `str` | Unique identifier (returned on click) |
|
|
105
105
|
| `label` | `str` | Button text (optional) |
|
|
106
106
|
| `icon` | `str` | Emoji/icon (optional) |
|
|
107
|
-
| `color` | `str` | `"blue"`, `"green"`, `"red"`, `"yellow"`, `"purple"` |
|
|
107
|
+
| `color` | `str` | Preset (`"blue"`, `"green"`, `"red"`, `"yellow"`, `"purple"`, `"slate"`) or hex (e.g., `"#94a3b8"`) |
|
|
108
|
+
| `style` | `dict` | Inline CSS styles for this button (optional) |
|
|
109
|
+
| `className` | `str` | Tailwind classes for this button (optional) |
|
|
110
|
+
| `href` | `str` | URL for link actions. External URLs (http/https) open in new tab (optional) |
|
|
108
111
|
|
|
109
112
|
#### Example
|
|
110
113
|
|
|
111
114
|
```python
|
|
115
|
+
# Using preset colors
|
|
112
116
|
clicked = section_header(
|
|
113
117
|
title="Executive Summary",
|
|
114
118
|
icon="📊",
|
|
@@ -118,8 +122,31 @@ clicked = section_header(
|
|
|
118
122
|
]
|
|
119
123
|
)
|
|
120
124
|
|
|
121
|
-
|
|
122
|
-
|
|
125
|
+
# Using hex colors and custom styling
|
|
126
|
+
clicked = section_header(
|
|
127
|
+
title="Custom Actions",
|
|
128
|
+
actions=[
|
|
129
|
+
{"id": "custom", "label": "Custom", "color": "#ff5733"},
|
|
130
|
+
{"id": "styled", "label": "Styled", "style": {"padding": "12px", "borderRadius": "20px"}}
|
|
131
|
+
]
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
# External link (opens in new tab)
|
|
135
|
+
section_header(
|
|
136
|
+
title="Resources",
|
|
137
|
+
actions=[
|
|
138
|
+
{"id": "docs", "label": "Documentation", "href": "https://docs.example.com", "icon": "📚"},
|
|
139
|
+
{"id": "github", "label": "GitHub", "href": "https://github.com", "color": "slate"}
|
|
140
|
+
]
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
# Internal page navigation
|
|
144
|
+
clicked = section_header(
|
|
145
|
+
title="Settings",
|
|
146
|
+
actions=[{"id": "home", "label": "Home", "icon": "🏠"}]
|
|
147
|
+
)
|
|
148
|
+
if clicked == "home":
|
|
149
|
+
st.switch_page("pages/home.py")
|
|
123
150
|
```
|
|
124
151
|
|
|
125
152
|
---
|
|
@@ -142,13 +169,17 @@ stat_card(
|
|
|
142
169
|
|
|
143
170
|
#### Colors
|
|
144
171
|
|
|
145
|
-
|
|
146
|
-
|
|
172
|
+
Supports preset color names or hex values:
|
|
173
|
+
|
|
174
|
+
| Preset | Border | Text |
|
|
175
|
+
|--------|--------|------|
|
|
147
176
|
| `"blue"` | `border-blue-500` | `text-blue-400` |
|
|
148
177
|
| `"green"` | `border-green-500` | `text-green-400` |
|
|
149
178
|
| `"red"` | `border-red-500` | `text-red-400` |
|
|
150
179
|
| `"yellow"` | `border-yellow-500` | `text-yellow-400` |
|
|
151
180
|
| `"purple"` | `border-purple-500` | `text-purple-400` |
|
|
181
|
+
| `"slate"` | `border-slate-500` | `text-slate-400` |
|
|
182
|
+
| `"#xxxxxx"` | Custom hex color | Custom hex color |
|
|
152
183
|
|
|
153
184
|
#### Example
|
|
154
185
|
|
|
@@ -163,6 +194,9 @@ with col3:
|
|
|
163
194
|
stat_card(label="Below (Underutil)", value="1", color="yellow")
|
|
164
195
|
with col4:
|
|
165
196
|
stat_card(label="Avg OEE", value="78.4%", color="blue")
|
|
197
|
+
|
|
198
|
+
# Using hex color
|
|
199
|
+
stat_card(label="Custom Color", value="42", color="#ff5733")
|
|
166
200
|
```
|
|
167
201
|
|
|
168
202
|
---
|
|
@@ -345,12 +379,15 @@ buttons = [
|
|
|
345
379
|
| `id` | `str` | Unique identifier (returned on click) |
|
|
346
380
|
| `label` | `str` | Button text (optional) |
|
|
347
381
|
| `icon` | `str` | Emoji/icon (optional) |
|
|
348
|
-
| `color` | `str` | `"blue"`, `"green"`, `"red"`, `"yellow"`, `"purple"`, `"slate"` |
|
|
382
|
+
| `color` | `str` | Preset (`"blue"`, `"green"`, `"red"`, `"yellow"`, `"purple"`, `"slate"`) or hex (e.g., `"#94a3b8"`) |
|
|
349
383
|
| `disabled` | `bool` | Disable the button |
|
|
384
|
+
| `style` | `dict` | Inline CSS styles for this button (optional) |
|
|
385
|
+
| `className` | `str` | Tailwind classes for this button (optional) |
|
|
350
386
|
|
|
351
387
|
#### Example
|
|
352
388
|
|
|
353
389
|
```python
|
|
390
|
+
# Using preset colors
|
|
354
391
|
clicked = button_group(
|
|
355
392
|
buttons=[
|
|
356
393
|
{"id": "view", "icon": "👁️", "label": "View"},
|
|
@@ -359,6 +396,14 @@ clicked = button_group(
|
|
|
359
396
|
]
|
|
360
397
|
)
|
|
361
398
|
|
|
399
|
+
# Using hex colors and custom styling
|
|
400
|
+
clicked = button_group(
|
|
401
|
+
buttons=[
|
|
402
|
+
{"id": "custom", "icon": "🎨", "color": "#ff5733"},
|
|
403
|
+
{"id": "styled", "label": "Styled", "style": {"padding": "12px"}}
|
|
404
|
+
]
|
|
405
|
+
)
|
|
406
|
+
|
|
362
407
|
if clicked == "delete":
|
|
363
408
|
st.warning("Delete clicked!")
|
|
364
409
|
```
|
|
@@ -408,7 +453,140 @@ chart_legend(
|
|
|
408
453
|
|
|
409
454
|
---
|
|
410
455
|
|
|
411
|
-
### 9.
|
|
456
|
+
### 9. Plotly Chart
|
|
457
|
+
|
|
458
|
+
Render Plotly charts with full interactivity and event callbacks.
|
|
459
|
+
|
|
460
|
+
```python
|
|
461
|
+
plotly_chart(
|
|
462
|
+
# Data source (one required)
|
|
463
|
+
figure: Any = None, # Plotly figure or dict
|
|
464
|
+
data: DataFrame = None, # pandas DataFrame
|
|
465
|
+
|
|
466
|
+
# DataFrame options (when using data=)
|
|
467
|
+
x: str = None, # Column name for x-axis
|
|
468
|
+
y: str | list = None, # Column name(s) for y-axis
|
|
469
|
+
color: str = None, # Column name for color grouping
|
|
470
|
+
chart_type: str = "line", # "line", "bar", "scatter", "area", "pie", "histogram"
|
|
471
|
+
title: str = None, # Chart title
|
|
472
|
+
|
|
473
|
+
# Plotly config
|
|
474
|
+
config: dict = None, # Plotly config options
|
|
475
|
+
|
|
476
|
+
# Event callbacks
|
|
477
|
+
on_click: bool = False, # Enable click events
|
|
478
|
+
on_select: bool = False, # Enable selection events
|
|
479
|
+
on_hover: bool = False, # Enable hover events
|
|
480
|
+
on_relayout: bool = False, # Enable zoom/pan events
|
|
481
|
+
|
|
482
|
+
# Styling
|
|
483
|
+
style: dict = None,
|
|
484
|
+
class_name: str = "",
|
|
485
|
+
key: str = None
|
|
486
|
+
) -> dict | None # Returns event dict or None
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
#### Using Plotly Figure
|
|
490
|
+
|
|
491
|
+
```python
|
|
492
|
+
import plotly.graph_objects as go
|
|
493
|
+
|
|
494
|
+
fig = go.Figure(
|
|
495
|
+
data=[
|
|
496
|
+
go.Scatter(x=[1,2,3,4,5], y=[10,15,13,17,20], mode='lines+markers', name='Sales'),
|
|
497
|
+
go.Bar(x=[1,2,3,4,5], y=[5,8,6,9,12], name='Orders')
|
|
498
|
+
],
|
|
499
|
+
layout=go.Layout(title='Sales Dashboard')
|
|
500
|
+
)
|
|
501
|
+
|
|
502
|
+
event = plotly_chart(
|
|
503
|
+
figure=fig,
|
|
504
|
+
on_click=True,
|
|
505
|
+
on_select=True,
|
|
506
|
+
style={"height": "400px"}
|
|
507
|
+
)
|
|
508
|
+
|
|
509
|
+
if event and event['type'] == 'click':
|
|
510
|
+
st.write(f"Clicked: {event['points']}")
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
#### Using DataFrame
|
|
514
|
+
|
|
515
|
+
```python
|
|
516
|
+
import pandas as pd
|
|
517
|
+
|
|
518
|
+
df = pd.DataFrame({
|
|
519
|
+
'month': ['Jan', 'Feb', 'Mar', 'Apr'],
|
|
520
|
+
'sales': [100, 150, 120, 180],
|
|
521
|
+
'orders': [50, 75, 60, 90]
|
|
522
|
+
})
|
|
523
|
+
|
|
524
|
+
# Simple line chart
|
|
525
|
+
event = plotly_chart(
|
|
526
|
+
data=df,
|
|
527
|
+
x='month',
|
|
528
|
+
y='sales',
|
|
529
|
+
chart_type='line',
|
|
530
|
+
title='Monthly Sales'
|
|
531
|
+
)
|
|
532
|
+
|
|
533
|
+
# Multiple y columns as bar chart
|
|
534
|
+
event = plotly_chart(
|
|
535
|
+
data=df,
|
|
536
|
+
x='month',
|
|
537
|
+
y=['sales', 'orders'],
|
|
538
|
+
chart_type='bar',
|
|
539
|
+
title='Sales vs Orders'
|
|
540
|
+
)
|
|
541
|
+
|
|
542
|
+
# Scatter with color grouping
|
|
543
|
+
event = plotly_chart(
|
|
544
|
+
data=df,
|
|
545
|
+
x='sales',
|
|
546
|
+
y='orders',
|
|
547
|
+
color='month',
|
|
548
|
+
chart_type='scatter'
|
|
549
|
+
)
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
#### Chart Types (DataFrame mode)
|
|
553
|
+
|
|
554
|
+
| Type | Description |
|
|
555
|
+
|------|-------------|
|
|
556
|
+
| `"line"` | Line chart with connected points |
|
|
557
|
+
| `"scatter"` | Scatter plot with markers only |
|
|
558
|
+
| `"bar"` | Vertical bar chart |
|
|
559
|
+
| `"area"` | Area chart (filled line) |
|
|
560
|
+
| `"pie"` | Pie chart (x=labels, y=values) |
|
|
561
|
+
| `"histogram"` | Histogram of x values |
|
|
562
|
+
|
|
563
|
+
#### Event Types
|
|
564
|
+
|
|
565
|
+
| Event | When Triggered | Data Returned |
|
|
566
|
+
|-------|----------------|---------------|
|
|
567
|
+
| `click` | User clicks a data point | `{type: 'click', points: [...]}` |
|
|
568
|
+
| `select` | User box/lasso selects points | `{type: 'select', points: [...]}` |
|
|
569
|
+
| `hover` | User hovers over a point | `{type: 'hover', points: [...]}` |
|
|
570
|
+
| `relayout` | User zooms/pans the chart | `{type: 'relayout', relayout: {...}}` |
|
|
571
|
+
|
|
572
|
+
#### Point Data Structure
|
|
573
|
+
|
|
574
|
+
Each point in the `points` array contains:
|
|
575
|
+
|
|
576
|
+
```python
|
|
577
|
+
{
|
|
578
|
+
"curveNumber": 0, # Index of the trace
|
|
579
|
+
"pointNumber": 2, # Index of the point in the trace
|
|
580
|
+
"pointIndex": 2, # Same as pointNumber
|
|
581
|
+
"x": "Mar", # X value
|
|
582
|
+
"y": 120, # Y value
|
|
583
|
+
"customdata": None # Custom data if provided
|
|
584
|
+
}
|
|
585
|
+
```
|
|
586
|
+
|
|
587
|
+
---
|
|
588
|
+
|
|
589
|
+
### 10. Form Select
|
|
412
590
|
|
|
413
591
|
A styled dropdown select input.
|
|
414
592
|
|
|
@@ -471,7 +649,7 @@ scenario = form_select(
|
|
|
471
649
|
|
|
472
650
|
---
|
|
473
651
|
|
|
474
|
-
###
|
|
652
|
+
### 11. Form Slider
|
|
475
653
|
|
|
476
654
|
A styled range slider input.
|
|
477
655
|
|
|
@@ -483,7 +661,7 @@ form_slider(
|
|
|
483
661
|
max_val: float, # Maximum value
|
|
484
662
|
step: float = 1, # Step increment
|
|
485
663
|
unit: str = "", # Unit suffix (e.g., "%", "hrs")
|
|
486
|
-
color: str = "blue", #
|
|
664
|
+
color: str = "blue", # Preset or hex color (e.g., "#94a3b8")
|
|
487
665
|
style: dict = None,
|
|
488
666
|
class_name: str = "",
|
|
489
667
|
key: str = None
|
|
@@ -493,7 +671,7 @@ form_slider(
|
|
|
493
671
|
#### Example
|
|
494
672
|
|
|
495
673
|
```python
|
|
496
|
-
# Percentage slider
|
|
674
|
+
# Percentage slider with preset color
|
|
497
675
|
threshold = form_slider(
|
|
498
676
|
label="Upper Threshold",
|
|
499
677
|
value=90,
|
|
@@ -514,20 +692,19 @@ hold_time = form_slider(
|
|
|
514
692
|
color="blue"
|
|
515
693
|
)
|
|
516
694
|
|
|
517
|
-
#
|
|
518
|
-
|
|
519
|
-
label="
|
|
520
|
-
value=
|
|
521
|
-
min_val=
|
|
522
|
-
max_val=
|
|
523
|
-
|
|
524
|
-
color="green"
|
|
695
|
+
# Slider with hex color
|
|
696
|
+
custom_slider = form_slider(
|
|
697
|
+
label="Custom Color",
|
|
698
|
+
value=50,
|
|
699
|
+
min_val=0,
|
|
700
|
+
max_val=100,
|
|
701
|
+
color="#ff5733"
|
|
525
702
|
)
|
|
526
703
|
```
|
|
527
704
|
|
|
528
705
|
---
|
|
529
706
|
|
|
530
|
-
###
|
|
707
|
+
### 12. Checkbox Group
|
|
531
708
|
|
|
532
709
|
A group of checkboxes.
|
|
533
710
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "streamlit-react-components"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "1.0.0"
|
|
8
8
|
description = "Reusable React-based Streamlit components with Tailwind CSS styling"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = {text = "MIT"}
|
|
@@ -13,6 +13,7 @@ from .common import (
|
|
|
13
13
|
step_indicator,
|
|
14
14
|
button_group,
|
|
15
15
|
chart_legend,
|
|
16
|
+
plotly_chart,
|
|
16
17
|
)
|
|
17
18
|
|
|
18
19
|
from .form import (
|
|
@@ -33,6 +34,7 @@ __all__ = [
|
|
|
33
34
|
"step_indicator",
|
|
34
35
|
"button_group",
|
|
35
36
|
"chart_legend",
|
|
37
|
+
"plotly_chart",
|
|
36
38
|
# Form components
|
|
37
39
|
"form_select",
|
|
38
40
|
"form_slider",
|