I would like to display a R dataframe with double lines between some rows.
For example to separate groups as in the picture below :
I looked at the functions formattable and kable but I didn't find anything.
CodePudding user response:
I have a solution which works with Rstudio :
library(gt); library(dplyr)
df = data.frame(Group = c("Tree", "Tree", "Flower", "Flower", "Flower"), Value = sample(c(1 : 20), 5));
df %>% gt() %>% tab_row_group(group = "", rows = 1:2)
Which gives :
Unfortunately I work with Jupyterlab, and here is an extract of the output I get with it :
CodePudding user response:
So with Jupyterlab It's almost good with this :
library(gt); library(dplyr)
df = tibble(Group = c("Tree", "Tree", "Flower", "Flower", "Flower"), Value = sample(c(1 : 20), 5), Letter = letters[1 : 5]);
kable(df) %>% group_rows(index = table(fct_inorder(df$Group)), label_row_css = "text-align: left; border-top: double") %>% as.character() %>% display_html()
which gives :
I just wish I could remove the groups title in bold (Tree and Flower). But I think It's quite ok.