admin管理员组文章数量:1336613
I need to make cells with rounded corners in {gt}, to make cells with color fill look like rounded rectangles. I know this is possible with {formattable}, and it should be possible with CSS border-radius: 5px;
.
What I'm trying to achieve can be seen in these {formattable} examples:
I need to make cells with rounded corners in {gt}, to make cells with color fill look like rounded rectangles. I know this is possible with {formattable}, and it should be possible with CSS border-radius: 5px;
.
What I'm trying to achieve can be seen in these {formattable} examples:
Share asked Nov 19, 2024 at 19:35 Bastián Olea HerreraBastián Olea Herrera 1,1008 silver badges24 bronze badges 1- 2 Here's a similar example: themockup.blog/static/resources/gt-cookbook-advanced#badges – Jon Spring Commented Nov 19, 2024 at 19:49
1 Answer
Reset to default 2This is kludgey, as I was having trouble combining the scaled (for shading determination) and raw (for display) values in one step. And I'd also prefer to map to a palette instead of manually calculating and HSL value. But it works as a demonstration of concept.
(Suggestions for improvement would be very welcome!)
add_badge <- function(x, y){
div_out <- htmltools::div(
style = paste0(
"display: inline-block; padding: 2px 12px; border-radius: 5px;",
"background: hsl(140, 50%, ",
scales::percent(y, accuracy = 1),
"); color: hsl(150, 10%, 50%);"
),
x
)
as.character(div_out) |>
gt::html()
}
mtcars |>
head() |>
dplyr::mutate(wt_scaled = scales::rescale(wt, to = c(0,1)),
wt_shade = purrr::map2(wt, wt_scaled, add_badge)) |>
gt()
本文标签: rHow to have cells with rounded corners in gtStack Overflow
版权声明:本文标题:r - How to have cells with rounded corners in {gt}? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742402880a2468236.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论