{"id":2791,"date":"2022-12-27T05:45:34","date_gmt":"2022-12-27T05:45:34","guid":{"rendered":"http:\/\/optimumsportsperformance.com\/blog\/?p=2791"},"modified":"2022-12-27T12:48:17","modified_gmt":"2022-12-27T12:48:17","slug":"collapsible-interactive-tables-with-reactable","status":"publish","type":"post","link":"https:\/\/optimumsportsperformance.com\/blog\/collapsible-interactive-tables-with-reactable\/","title":{"rendered":"Collapsible interactive tables with {reactable}"},"content":{"rendered":"<p>Since I&#8217;ve been talking about approaches to sharing and visualizing athlete performance data lately, I decided to put together some quick code for developing collapsible tables with the {<strong>reactable<\/strong>} package in R.<\/p>\n<p>I like Reactable tables because they offer a simple framework for quickly building interactive html reports for your end user. You can also embed these into {<strong>Rmarkdown<\/strong>} reports or {<strong>shiny<\/strong>} apps.<\/p>\n<p><em><strong>Why do we need collapsible tables?<\/strong><\/em><\/p>\n<ol>\n<li>The collapsible nature educes the amount of real estate they take up in the end user&#8217;s report. Instead of a big long table, the user can take the information in chunks without getting distracted.<\/li>\n<li>When embedding a collapsible table into your {<strong>Rmarkdown<\/strong>} or {<strong>shiny<\/strong>} reports, it makes them look less busy.<\/li>\n<li>In meetings, if you have a large number of athletes to discuss, spread across several positions, a large table allows the meeting attendees to have &#8220;<em>busy eyes<\/em>&#8220;, as they scan up and down the table and get ahead of things. With a collapsible table, you are able to direct their attention to the aspects you are discussing.<\/li>\n<\/ol>\n<p>You can access all of the code on my <strong><span style=\"color: #0000ff;\"><a style=\"color: #0000ff;\" href=\"https:\/\/github.com\/pw2\/R-Tips-Tricks\/blob\/master\/collapsible%20tables%20with%20reactable.R\">GITHUB page<\/a> <\/span><\/strong><span style=\"color: #000000;\">and use it as a template to construct your own collapsible interactive tables. I tried to add several different styling options to the various columns so that it covers many of the things people attempt to do when building reports (e.g., conditional formatting, conditional formatting using information contained in a secondary column, rounding numbers, converting values to percentages, hiding columns you don&#8217;t want in the table, etc.).<\/span><\/p>\n<p>To play with the html table yourself, <strong>CLICK HERE &gt;&gt;<\/strong> <a href=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/collapsible-tables-with-reactable.html\"><strong><span style=\"color: #0000ff;\">collapsible tables with reactable<\/span><\/strong><\/a><\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Examples of the table<\/strong><\/span><\/p>\n<p>The data came from the {<strong>Lahman<\/strong>} baseball data set in R. I build a table that nests the players within their respective teams and the teams nested within their respective league (NL or AL). So, this table has 2 structures of collapsing. The table of the table looks like this:<a href=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.16.42-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-2792\" src=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.16.42-PM-1024x160.png\" alt=\"\" width=\"625\" height=\"98\" srcset=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.16.42-PM-1024x160.png 1024w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.16.42-PM-300x47.png 300w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.16.42-PM-768x120.png 768w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.16.42-PM-624x98.png 624w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.16.42-PM.png 1589w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><br \/>\nNotice that all we see are the headers (which I&#8217;ve set a filterable function under) and the top level of nesting (league).<\/p>\n<p>If you click one of the league drop downs, you expand out and see the second level of testing (teams):<\/p>\n<p><a href=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.16.51-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-2793\" src=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.16.51-PM-1024x438.png\" alt=\"\" width=\"625\" height=\"267\" srcset=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.16.51-PM-1024x438.png 1024w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.16.51-PM-300x128.png 300w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.16.51-PM-768x329.png 768w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.16.51-PM-624x267.png 624w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.16.51-PM.png 1593w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><br \/>\nFinally, you can click down into any team and obtain the list of players and their stat lines:<\/p>\n<p><a href=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.17.37-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-2794\" src=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.17.37-PM-1024x323.png\" alt=\"\" width=\"625\" height=\"197\" srcset=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.17.37-PM-1024x323.png 1024w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.17.37-PM-300x95.png 300w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.17.37-PM-768x243.png 768w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.17.37-PM-624x197.png 624w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.17.37-PM.png 1596w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><\/p>\n<p>Within the code, you&#8217;ll notice that I created a simple z-score for each of the stats. The shading is relative to the z-scores; however, to de-clutter the table, I&#8217;ve hidden those columns but retain their meaning by using the conditional formatting.<\/p>\n<p>If a person is at the highest level of nesting (league) and wants to just search for a player, that is also possible:<\/p>\n<p><a href=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.18.17-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-2795\" src=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.18.17-PM-1024x157.png\" alt=\"\" width=\"625\" height=\"96\" srcset=\"https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.18.17-PM-1024x157.png 1024w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.18.17-PM-300x46.png 300w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.18.17-PM-768x117.png 768w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.18.17-PM-624x95.png 624w, https:\/\/optimumsportsperformance.com\/blog\/wp-content\/uploads\/2022\/12\/Screen-Shot-2022-12-26-at-9.18.17-PM.png 1589w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><\/p>\n<p>As you can see, collapsible interactive tables can be a great way to share data in a clean way and prevents the end user from being overwhelmed by long and extensive amounts of data across many rows and columns.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since I&#8217;ve been talking about approaches to sharing and visualizing athlete performance data lately, I decided to put together some quick code for developing collapsible tables with the {reactable} package in R. I like Reactable tables because they offer a simple framework for quickly building interactive html reports for your end user. You can also [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[45,43,42,27],"tags":[],"class_list":["post-2791","post","type-post","status-publish","format-standard","hentry","category-r-tips-tricks","category-sports-analytics","category-sports-science","category-strength-and-conditioning"],"_links":{"self":[{"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/posts\/2791","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/comments?post=2791"}],"version-history":[{"count":2,"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/posts\/2791\/revisions"}],"predecessor-version":[{"id":2798,"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/posts\/2791\/revisions\/2798"}],"wp:attachment":[{"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/media?parent=2791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/categories?post=2791"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/optimumsportsperformance.com\/blog\/wp-json\/wp\/v2\/tags?post=2791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}