0

I have a table like below. I am grouping data by "name" and counting the records for each name. I want to add a sparkling using the "date" column to the table but haven't come across any documentation how to do that. I read about formattable R package but for that dates have to be in columns. I'll appreciate any help!

id name date
1 John 2018-05-30
2 John 2018-06-14
3 John 2018-06-15
4 John 2018-07-01
5 Miley 2018-01-01
6 Miley 2019-06-21
7 Miley 2020-05-19

This is how I am grouping. I now want to a another column to the table with the sparkline.

spark <- project %>%
  group_by(name) %>%
  summarise(
    chart = spk_chr(
      date,
      type="line")
  ) %>%
  gt() %>%
  fmt_markdown(columns = vars(chart))
p_html <- gt:::as.tags.gt_tbl(spark)
p_html <- htmltools::attachDependencies(p_html, htmlwidgets::getDependency("sparkline"))
print(p_html, browse = interactive())

This produces an empty table.

akang
  • 566
  • 2
  • 15
  • Does this answer your question? [Is it possible to use sparkline with gt?](https://stackoverflow.com/questions/64479291/is-it-possible-to-use-sparkline-with-gt) – manro Nov 10 '21 at 14:31
  • @manro This doesn't show how to handle dates. Also, if there a non html way of handling it would be great. But its a nice lead. Thanks – akang Nov 10 '21 at 14:37
  • here is with date: https://stackoverflow.com/questions/64041418/sparkline-returns-blank-table but in the shiny – manro Nov 10 '21 at 14:45
  • What package(s) are you using? There are a few I think that support it, please be explicit. Also, I see no code that is attempting to render a table for reports, it's just summarizing a frame into another frame here. – r2evans Nov 10 '21 at 14:49
  • I do not have a package preference. I updated the code. – akang Nov 10 '21 at 14:53

0 Answers0