@@ -118,17 +118,20 @@ set.seed(20)
118
118
```
119
119
120
120
``` {r tags, eval=FALSE}
121
+ library(htmltools)
122
+
121
123
orders <- data.frame(
122
124
Order = 2300:2304,
123
125
Created = seq(as.Date("2019-04-01"), by = "day", length.out = 5),
124
126
Customer = sample(rownames(MASS::painters), 5),
125
- Status = sample(c("Pending", "Paid", "Canceled"), 5, replace = TRUE)
127
+ Status = sample(c("Pending", "Paid", "Canceled"), 5, replace = TRUE),
128
+ stringsAsFactors = FALSE
126
129
)
127
130
128
131
reactable(orders, columns = list(
129
132
Status = colDef(cell = function(value) {
130
133
class <- paste0("tag status-", tolower(value))
131
- htmltools:: div(class = class, value)
134
+ div(class = class, value)
132
135
})
133
136
))
134
137
```
@@ -161,6 +164,34 @@ reactable(orders, columns = list(
161
164
``` {r ref.label="tags", echo=FALSE}
162
165
```
163
166
167
+ ``` {r}
168
+ library(htmltools)
169
+
170
+ status_badge <- function(color = "#aaa", width = "9px", height = width) {
171
+ span(style = list(
172
+ display = "inline-block",
173
+ marginRight = "8px",
174
+ width = width,
175
+ height = height,
176
+ backgroundColor = color,
177
+ borderRadius = "50%"
178
+ ))
179
+ }
180
+
181
+ reactable(orders, columns = list(
182
+ Status = colDef(cell = function(value) {
183
+ color <- switch(
184
+ value,
185
+ Paid = "hsl(214, 45%, 50%)",
186
+ Pending = "hsl(30, 97%, 70%)",
187
+ Canceled = "hsl(3, 69%, 50%)"
188
+ )
189
+ badge <- status_badge(color = color)
190
+ tagList(badge, value)
191
+ })
192
+ ))
193
+ ```
194
+
164
195
## Bar charts
165
196
166
197
There are different ways to create bar charts, but here's
0 commit comments