Top R Packages for Visualizing Table Data - Make Stunning Tables in Minutes

Estimated time:
time
min

Visualizing table data is no small task. It requires both data manipulation and data visualization skills from the technical end. It also requires knowledge about your audience. Ask yourself — For whom are you visualizing the data? Do you need interactivity? Will you include the table in a web application? The list of questions goes on and on. Thankfully, we have a solution. This article brings you answers on the best R packages for visualizing table data. We’ll go over four of them today, and we’ll also show you how to tie them together in an interactive R Shiny application. Table of contents: <ul><li><a href="#what-is-table-data">What is Table Data?</a></li><li><a href="#why-use-r-over-excel-python-or-javascript">Why Use R Over Excel, Python, or JavaScript?</a></li><li><a href="#best-packages">Best R Packages for Visualizing Table Data</a></li><li><a href="#r-studio-contest">RStudio Table Contest — Sign Up Now</a></li><li><a href="#conclusion">Conclusion</a></li></ul> <hr /> <h2 id="what-is-table-data">What is Table Data?</h2> Think of table data as something aggregated from tabular data. Tabular data is made of rows and columns, and a place where they intersect gives you specific information about a single record — for example, the number of people living in Poland in 2021. Tabular data usually isn’t the best candidate for presenting visually with a table. The reason? It can be huge in dimension, and you’re only interested in a small subset. For example, imagine you had population data for the entire world, and you’re only interested in a single country. You could aggregate the data, so you’re left with a small, presentable subset. Let’s take a look at one such dataset to drive the point home. You should have the <code>dplyr</code> and <code>gapminder</code> packages installed. Let’s import them both and check how the dataset looks like: <script src="https://gist.github.com/darioappsilon/1e5bf43c4c944f33818949ba9beb4e6b.js"></script> &nbsp; <img class="size-full wp-image-8617" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b26721d4b7904152072513_1.webp" alt="Image 1 - The GapMinder dataset" width="1034" height="334" /> Image 1 - The GapMinder dataset And there’s your tabular data. It isn’t directly presentable, as it has over 1700 rows. No one wants to go over that table manually, so let’s aggregate it to something more presentable. We’ll keep only the records for Poland, tracked through the <code>year</code> and <code>lifeExp</code> columns. You can do the aggregation effortlessly with <code>dplyr</code>: <script src="https://gist.github.com/darioappsilon/9fb0a676a24448c0b6338df4c95eb6db.js"></script> <img class="size-full wp-image-8618" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b7d500be40ac3284ad7432_e2f845ce_2.webp" alt="Image 2 - Life expectancy in Poland over time" width="330" height="588" /> Image 2 - Life expectancy in Poland over time Now that’s something you could present in a table format. How do you do that? There’s a lot of R packages for visualizing table data, but first, let’s discuss why you should use R in the first place. <h2 id="why-use-r-over-excel-python-or-javascript">Why Use R Over Excel, Python, or JavaScript?</h2> Why bother with programming languages if you can style tables however you want with Excel? Well, you’re leaving a lot of customization on the table by sticking with Excel. Also, the table won’t be interactive and don’t even get me started on reproducibility. But what about a dedicated BI tool, such as <strong>Tableau</strong> or <strong>PowerBI</strong>? Honestly, we’ve used them at Appsilon, and they generally have a lot of going for them. But like every tool, these aren’t flawless. Make sure to read our detailed comparisons to R Shiny: <ul><li><a href="https://appsilon.com/powerbi-vs-r-shiny/" target="_blank" rel="noopener noreferrer">PowerBI vs. R Shiny: Two Popular Excel Alternatives Compared</a></li><li><a href="https://appsilon.com/tableau-vs-r-shiny/" target="_blank" rel="noopener noreferrer">Tableau vs. R Shiny: Which Excel Alternative Is Right For You?</a></li></ul> <blockquote><strong>Want to integrate Shiny with Tableau? Check out the <a href="https://blog.rstudio.com/2021/10/12/rstudio-connect-2021-09-0-tableau-analytics-extensions/" target="_blank" rel="noopener noreferrer">RStudio Connect Tableau Analytics Extensions for R and Python</a>.</strong></blockquote> JavaScript is a different story. You can definitely use it to make stunning tables and it probably has the largest number of data visualization libraries. But here’s the thing — JavaScript is not a programming language for data professionals. Nobody uses JavaScript as a go-to language for data science and machine learning. If you’re into web application and dashboard development, it might be a viable option. For data professionals, it almost always boils down to R or Python. Python is a general-purpose programming language with a strong background in data science and machine learning. R can also do pretty much everything but is tailored more for advanced stats and statistical modeling. <blockquote><strong>Are you new to R? <a href="https://appsilon.com/r-for-programmers/" target="_blank" rel="noopener noreferrer">Here are 6 essential things you do with R as a programmer.</a></strong></blockquote> You can’t go wrong with R or Python, and the choice will most likely boil down to the personal preference, or the preference of the company you work for. At Appsilon, we’ve chosen R as a programming language of choice for data science, machine learning, data visualization, and dashboard development. It’s proven to be better for what we do, but your mileage may vary. We also have experience with Python and its data science libraries. Read our detailed Pandas vs. dplyr comparison below: <ul><li><a href="https://appsilon.com/pandas-vs-dplyr/" target="_blank" rel="noopener noreferrer">Python’s Pandas vs. R’s dplyr</a> — Which Is The Best Data Analysis Library</li></ul> With that out of the way, let’s explore the top R packages for visualizing table data. <h2 id="best-packages">R Packages for Visualizing Table Data</h2> We’ll now go over a collection of R packages for visualizing table data. If you want to follow along, please ensure you have <code>dplyr</code>, <code>gapminder</code>, <code>gt</code>, <code>kableExtra</code>, <code>DT</code>, <code>plotly</code>, and <code>shiny</code> installed. We’ll use the previously aggregated life expectancy data for Poland as a table data source. <h3>gt</h3> The <code>gt</code> package is designed for making display tables, meaning it doesn’t provide any input to the user. It might be a deal-breaker if you want the ability of filtering data on the fly. Nevertheless, <code>gt</code> makes it so easy to get started: <script src="https://gist.github.com/darioappsilon/9e2e4bec1b91ab5156df28b033f1e428.js"></script> Yes, that’s it! The table will look plain, but you can always add styles later: <img class="size-full wp-image-8619" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b26714ef69c7c93dc4750f_3-1.webp" alt="Image 3 - Unstlyled gt table" width="1328" height="1170" /> Image 3 - Unstyled gt table Let’s tweak it a bit — we’ll add a title, rename the columns, add a source node, and change the fill color for the first cell: <script src="https://gist.github.com/darioappsilon/87fd351bf5a44ad685ea3eb92a569979.js"></script> <img class="size-full wp-image-8620" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b26714af8bedb2b03a6252_4-1.webp" alt="Image 4 - Styled gt table" width="1224" height="1312" /> Image 4 - Styled gt table Explore the in's-and-outs of the <a href="https://gt.rstudio.com/" target="_blank" rel="noopener noreferrer">gt package from RStudio</a>. The package works well with R markdown and Quarto and can be applied across industry and academia. The <code>gt</code> package is a good solution if you need minimalistic-looking tables without input controls. With some creative input,<code class="language-r">gt</code>can be used to build some <a href="https://blog.rstudio.com/2020/12/23/winners-of-the-2020-rstudio-table-contest/" target="_blank" rel="noopener noreferrer">contest-winning tables</a>. Let’s explore one similar alternative next. <h3>kableExtra</h3> The <code>kableExtra</code> package lets you create display tables just like <code>gt</code>, but packs rich theme support. It’s also a bit more flexible than the previous package. Getting started is close to effortless, once again: <script src="https://gist.github.com/darioappsilon/bd4f1acaf0cc538d02cd5f7d7bdcc858.js"></script> <img class="size-full wp-image-8621" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b267244b3ab6e1ead878a3_5.webp" alt="Image 5 - Unstyled kableExtra table" width="1656" height="1224" /> Image 5 - Unstyled kableExtra table The styling is quite minimalistic once again, but <code>kableExtra</code> has many ready-to-go themes you can use (<a href="https://cran.r-project.org/web/packages/kableExtra/vignettes/awesome_table_in_html.html" target="_blank" rel="noopener noreferrer">source</a>). Let’s see how the <em>material</em> theme looks like — we’ll also add a footnote and a stripped look that changes on hover: <script src="https://gist.github.com/darioappsilon/d193736e7d12c48bdee913fccda8ce7a.js"></script> <img class="size-full wp-image-8622" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b267259023e631a995a128_6.webp" alt="Image 6 - Styled kableExtra table" width="1804" height="1218" /> Image 6 - Styled kableExtra table Just like <code>gt</code>, it’s a good option to go with if you don’t want input controls out of the box. If you do, you’re in luck — the next package has it built-in. <h3>DT</h3> The <code>DT</code> package in R provides an interface to the <code>DataTables</code> library in JavaScript. It can display matrices and data frames as tables, and provides filtering, pagination, and sorting out of the box. It requires even less code to get started than the previous two: <script src="https://gist.github.com/darioappsilon/a076b69ef9c5d38209e3f56df52fadd3.js"></script> <img class="size-full wp-image-8623" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b26726152c9d10f464d82d_7.webp" alt="Image 7 - Unstyled DT table" width="1648" height="1316" /> Image 7 - Unstyled DT table Yes, the table could definitely benefit from some styling, but offers everything the end-user might need by default. You can extend its functionality further by adding column-level filtering. Here’s the code you’ll need to do that, and also change the column names and add a caption: <script src="https://gist.github.com/darioappsilon/ed6b807065338ea343fe498ce6742c50.js"></script> <img class="size-full wp-image-8624" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b26726b599c3cee3fe020b_8.webp" alt="Image 8 - Styled DT table" width="1642" height="1312" /> Image 8 - Styled DT table Here’s what happens if you click on the column-level filters: <img class="size-full wp-image-8625" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b267279a4bb348569fac2c_9.webp" alt="Image 9 - Filtering DT tables" width="1654" height="1332" /> Image 9 - Filtering DT tables It’s astonishing to see so much functionality available by default. Coding that logic manually would take hours for experienced developers, which makes <code>DT</code> an ultimate time-saver. The <code>DT</code> package might be the best solution for dashboard developers, as it won’t overflow the page if the table has many rows. Also, the search, pagination, and filtering capabilities are implemented for you, so it’s one less thing to worry about. <h3>Plotly</h3> Plotly is a go-to package for interactive data visualizations. It’s available for R, Python, and JavaScript, and you can use it in R Shiny dashboards without any issues. Regular charts (line, bar, scatter…) look spectacular, but how about tables? Let’s find out. You can use the following snippet to create a basic table from our subset: <script src="https://gist.github.com/darioappsilon/70295bbc4bade210e0ed8516fe53d01b.js"></script> <img class="size-full wp-image-8626" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b2672851c813d4289086be_10.webp" alt="Image 10 - Unstlyled Plotly table" width="1536" height="658" /> Image 10 - Unstyled Plotly table The table doesn’t look the best by default and requires a lot more code when compared to the previous options. Styling the table, well, takes time: <script src="https://gist.github.com/darioappsilon/c8cb6108a08f9f9307ffce6bed3ee63b.js"></script> <img class="size-full wp-image-8627" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b2672893d27c1f5c8d5254_11.webp" alt="Image 11 - Styled Plotly table" width="1544" height="780" /> Image 11 - Styled Plotly table To summarize, Plotly tables look and feel horrible if you consider it’s one of the go-to packages for data visualization. You can make it work, sure, but is it really worth the trouble? <h3>Tying it All Together</h3> You can use all three of the mentioned R packages for visualizing table data when building web applications with R and R Shiny. To demonstrate, we’ll create a simple Shiny dashboard that: <ul><li>Has a dropdown menu for country selection.</li><li>Has four separated parts to showcase tables from four different packages.</li><li>Updates the tables automatically as you change the country.</li></ul> You can implement all of that in less than 100 lines of code. You’ll understand pretty much everything from the <code>server</code>, as it contains the code for generating tables. The <code>ui</code> will contain placeholders for the charts separated with different headings and UI elements. Here’s the entire code: <script src="https://gist.github.com/darioappsilon/3a7c111cd29dbf74cbdee6dbd64cbd19.js"></script> It is somewhat of a lengthy file, but it should feel readable even if you’re not an R Shiny expert. You should see the following once you run it: <img class="size-full wp-image-8628" src="https://webflow-prod-assets.s3.amazonaws.com/6525256482c9e9a06c7a9d3c%2F65b2673f5b9974d4f565be44_12.gif" alt="Image 12 - R Shiny dashboard for table demonstration" width="906" height="896" /> Image 12 - R Shiny dashboard for table demonstration Not too bad, right? If you’ve developed dashboards with Python’s Dash, then R Shiny will feel a bit different at first. We’ve written a full comparison between the two to get you started: <ul><li><a href="https://appsilon.com/dash-vs-shiny/" target="_blank" rel="noopener noreferrer">Plotly Dash vs. R Shiny</a> — Which to Choose in 2021 and Beyond</li></ul> In a nutshell, both libraries work wonders, and the decision will likely boil down to the ecosystem you’re using. At Appsilon, we’ve used both but mainly stick to R Shiny for enterprise applications. <blockquote><strong>Are your dashboards slow? Consider <a href="https://appsilon.com/apache-arrow-in-r-supercharge-r-shiny-dashboards/" target="_blank" rel="noopener noreferrer">Apache Arrow to supercharge your R Shiny dashboards</a>.</strong></blockquote> <h2 id="r-studio-contest">RStudio Table Contest</h2> Do you think you have what it takes to produce award-winning data table visualizations? You’re in luck, as RStudio is holding a <a href="https://blog.rstudio.com/2021/09/30/rstudio-table-contest-2021/" target="_blank" rel="noopener noreferrer">2021 Table Contest</a>. It runs from September 30th to November 15th, 2021, so there’s still time to apply. <blockquote><strong>What are you up against? <a title="2020 Table Contest" href="https://blog.rstudio.com/2020/12/23/winners-of-the-2020-rstudio-table-contest/" target="_blank" rel="noopener noreferrer">Browse the phenomenal entries from the 2020 Table Contest</a>.</strong></blockquote> You should consider a couple of things before applying: <ul><li>Every submission must include all code and data that was used, so the visualization can be reproduced.</li><li>You can submit an entry as an R Markdown document, a repository, or an RStudio Cloud project.</li><li>You can use any table-making package available in R.</li><li>You can submit an entry either as a <strong>single table example</strong> (an example of a common table popular in a specific field) or as a <strong>tutorial</strong> (teaching how to craft an excellent table).</li></ul> Everything looks good? You can submit your entry for the contest by filling in an <a href="https://community.rstudio.com/latest" target="_blank" rel="noopener noreferrer">online form</a>, just make sure to fill it before November 15th, 2021 at midnight Pacific Time. <strong>What’s in it for you?</strong> RStudio has excellent prices for the winners: <ul><li><strong>The Grand Prize</strong> — A randomized combination of RStudio t-shirts, books, and mugs, plus the prizes below.</li><li><strong>Runner-Up</strong> — Face time with people making table-making packages, and a one-year subscription to the <a title="Shinyapps.io" href="https://www.shinyapps.io/?_ga=2.242634439.458070270.1635157790-1259896586.1634278474" target="_blank" rel="noopener noreferrer">Shinyapps.io</a> Basic plan, plus the prize below.</li><li><strong>Honorable Mentions</strong> — A larger-than-large helping of hexagon-shaped stickers for RStudio packages, plus a side of hex for table-making packages.</li></ul> You can find more details about the <a href="https://blog.rstudio.com/2021/09/30/rstudio-table-contest-2021/" target="_blank" rel="noopener noreferrer">RStudio Table Contest here</a>. <hr /> <h2 id="conclusion">Conclusion</h2> To summarize, we believe R is the most promising option for visualizing table data. We’ve used the mentioned packages countless times when developing enterprise R Shiny dashboards, and we never looked back. With a little ingenuity, you can add creative flair to your tables and better communicate your results. <blockquote><strong>Looking to participate in RStudio Table Contest? Check our <a href="https://demo.appsilon.com" target="_blank" rel="noopener noreferrer">R Shiny Dashboard gallery</a> for inspiration.</strong></blockquote> If you’re thinking about a career as an R Shiny developer, take a look at our <a href="https://appsilon.com/how-to-start-a-career-as-an-r-shiny-developer/" target="_blank" rel="noopener noreferrer">recent guide</a>. It contains many tips and resources for those starting out, and those with years of experience. Plus, you’ll also find out how to get hired at Appsilon — an industry leader building the world’s most advanced R Shiny applications for Fortune 500 companies.

Contact us!
Damian's Avatar
Damian Rodziewicz
Head of Sales
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
shiny
shiny dashboards
r
data visualization
rstudio
tutorials