Home > database >  Format a table in formattable R
Format a table in formattable R

Time:11-20

I have a table that I am plotting in R like below. But my code only produces table with sparklines for half the table. Also is there a way to set number of entries that the table shows. I a interested in all 30 rows on one page.

structure(list(Name = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 
2L, 2L, 2L, 2L, 2L), .Label = c("John", "Mary"), class = "factor"), 
    year = c(2021L, 2021L, 2021L, 2021L, 2021L, 2021L, 2021L, 
    2021L, 2021L, 2021L, 2021L, 2021L), week = c(1L, 2L, 3L, 
    4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L), Total = c(3L, 2L, 0L, 
    0L, 1L, 0L, 3L, 2L, 0L, 0L, 1L, 0L)), class = "data.frame", row.names = c(NA, 
-12L))

My code    
test1 %>% 
      group_by(Name) %>%
      summarise("Weekly_trend" = spk_chr(Total)) %>%
      formattable() %>%
      as.datatable() %>%
      spk_add_deps()

CodePudding user response:

In as.datatable() you can add the option of how large you want your page length to be. In this case, I am setting the page length to 30.

full_test %>% 
  group_by(Name) %>%
  summarise("Weekly_trend" = spk_chr(Total)) %>%
  formattable() %>%
  as.datatable(options = list(pageLength = 30)) %>%
  spk_add_deps()
  •  Tags:  
  • r
  • Related