Welcome to a practical guide to help you build professional grade R shiny app dashboards in 2021. By applying the tips, frameworks, packages and ideas in this guide, you will discover new ways to inform and wow your colleagues and clients with your R shiny app dashboards.
In this guide you’ll find both original content and curated resources to:
+ Build R shiny apps from scratch
+ Select the optimal dashboard framework for your R shiny app dashboard
+ R packages to build interactive, professional quality data visualizations
+ Improve the user experience and dashboard speed tricks
+ All the ways you can deploy and share R shiny app dashboards
+ Lessons from a dashboard veteran for better R shiny app dashboards
Let’s dive right in.
Love your R programs? Want to share them online, complete with dynamic data interaction capabilities? Then the shiny package on CRAN is for you. Start with your handcrafted R program for data access, analyses and graphs. Add the shiny package and you can build a shiny web app in R in minutes. You interact with your R shiny app in your favorite web browser.
Interact with the sample R shiny app above, hosted on YakData ConnectR
A shiny app is an interactive display of data on a web page driven by the statistical power of R. Supported in all modern web browsers, it can be either for personal use or published to a server for sharing with anyone from a small team to the entire world.
Behind the scenes, an R shiny app has a UI (user interface) function and a server function. The UI function describes what data displays to show, what controls will be available and other relevant information like page titles and chart titles. The server function contains modular snippets of your R code to access data, transform data and specify data displays such as maps, charts, graphs and tables to be passed to the UI function. The crucial step: your server function can dynamically react to changes in the control inputs from the UI function. This is how shiny selectively reruns parts of your R code based on user interactions with the web page.
So, your R shiny app audience answers their questions on the spot about the data in your app by interacting with the user interface. The linkage between the user interface and server function is called reactivity, which is basically the display updating based on user interaction with components of the shiny app. These interactions are all programmed by you, the creator of the app.
With your R shiny app, you can display charts, tables, maps and essentially any data display output you build in R. R shiny apps allow you and your team to focus on the analysis results to better understand the signals and nuance in your data.
R shiny apps can be just for personal usage or shared with the team using open-source RStudio Shiny Server, RStudio’s shinyapps.io, YakData’s ConnectR, RStudio’s Shiny Server Pro, RStudio Connect or shinyProxy.
You can embed R shiny apps on a web site using an iframe. This is a simple, widely used method to add them to a corporate web site, a personal blog or hand-crafted web pages.
Interact with a live forecasting R shiny app on YakData ConnectR. This example app uses one of the advanced dashboard frameworks, so it is a fairly technical.
Here are four excellent tutorials from expert R users in the wild for learning how to build R shiny apps. If you complete all four, you’ll be prepared to go a long way with the dashboard resources in this Ultimate Guide.
In this in-depth tutorial by Dean Attali, you’ll build an R shiny app that will “… walk through all the steps of building a Shiny app using a dataset that lets you explore the products available at the BC Liquor Store. The final version of the app, including a few extra features that are left as exercises for the reader…”
In this tutorial by Yasmine Hejazi of Towards Data Science, you can “create a two-page Shiny application using Mario Kart 8 character data found in Kaggle. The application will consist of an introduction page and a visualization page. In our visualization page, we will build an interactive vertical bar chart where the user can select which variable they would like to see”
From the book, Mastering Shiny by Hadley Wickham, build your first R shiny app which will show “… you the minimum boilerplate needed for a Shiny app, and then you’ll learn how to start and stop it. Next you’ll learn the two key components of every Shiny app: the UI (short for user interface) which defines how your app looks, and the server function which defines how your app works…“
In this tutorial by Martin Henze of Heads or Tails, you’ll construct an R shiny app that “… allows you to choose the number of coin flips as well as the probability for Heads using slider bars. It visualises the resulting total numbers of Heads vs Tails as a reactive bar plot…”
Reactivity in your R shiny app goes beyond the standard behavior of an R program, which runs from top to bottom in a linear fashion. An R shiny app can have sections that run like a standard R program, in a linear fashion and just once, but it also can have sections that run on-demand based on user interaction with your app on the web page.
Reactivity could be as simple as changing a text string on the web page, like a title of a chart, or could be as intensive as running the original database query that fed every display on the page and running complex analyses on this new query before updating the page charts, graphs and tables.
As the creator of an R shiny app, you determine what controls will appear on the web page. These controls, in turn, determine what inputs can be sent back to the R shiny app program. This is a simplistic way to explain how an R shiny app can “react” to the users desired changes.
Keep in mind that in a production R shiny app, the R session is using resources on your server AND waiting for users to request updates to their currently opened app. So, if you open an exceptionally large data source and keep it open in your server function, that memory is used on your server and not available for other purposes until the app times out from inactivity.
Here are two resources to help you gain a more in-depth understanding of reactivity in your R shiny apps.
Here is a detailed discussion about reactivity at the shinyData blog.
For an in-depth review of reactivity, here is Garrett Grolemund of RStudio on how to understand reactivity in R.
If you are a visual learner like me, seeing a lot of great R shiny app examples may be just the inspiration you need to keep going on your R shiny app odyssey! Browsing galleries of R shiny apps can help you gain a better understanding of what is possible, common design patterns, various appearance themes that are popular and more. Galleries can also be a good way to explain R shiny apps to a less technical audience at your organization.
Here are live, interactive galleries of R shiny apps:
R shiny apps gallery on YakData ConnectR.
For a look at some statistical heavy-weight R shiny apps, check out the EU funded TquanT project R shiny app gallery.
Over at Appsilon, they have an impressive range of R shiny app examples in their demo gallery.
Of course, the creators of the shiny package have an in-depth range of examples in the RStudio shiny gallery.
A beautiful example by Joy P. Wyckoff, How to make interactive maps in R Shiny.
A bright look at sports, An R Shiny Tutorial: All you Need to Know by Cherukuri Sindhu.
Data Science Ph.D. examples at the UVA Stat Lab, Interactive Visualization and Web Apps with Shiny.
Over 180 shiny examples by RStudio. Almost every detail and nuance of shiny apps has an example app here.
The original Shiny::cheatsheet by Garrett Grolemund at RStudio.
In 2021, there are many package options for building pro-quality dashboards with your R shiny app. After a systematic review of our client work and exciting new options, here are my top three picks for building pro-quality R shiny app dashboards with five more excellent choices, depending on your project and organization standards.
In this review of framework packages, I show:
+ An example screenshot of the framework in use.
+ Background on the framework.
+ The RStudio CRAN ranking of downloads for that package in December 2020.
+ How long each package has been under development.
+ Where you can find the development page of the package.
+ Whether the framework is responsive to smaller screens/screen resizing.
+ And my opinion of the complexity of applying the framework to your R shiny app.
All of these frameworks appear to be under active development, which is a good trait. And all appear to be battle-hardened through multiple releases or a significant number of resolved bugs/issues, enough to be confident of their quality to use in professional-grade projects. Ultimately, your choice may be a mix of preference, practical issues, organization standards and reusability for other projects you may build in 2021 and beyond.
Here is our choice of top R shiny app dashboard frameworks for 2021. The first three in this table are ranked by our preference in project use and the other five options are also great alternatives.
|Framework||CRAN Rank||Relative Download Rank||Years Under Development||Responsive sizing||Complexity to Use|
An easy but powerful way to add many additional capabilities to shinydashboard-built R shiny app dashboards. It enhances the shinydashboard framework with a right sidebar, additional left-side header controls, multiple new box controls including a flipbox and widgetbox, new buttons for apps and social media, new box elements including sidebars, accordions and timelines and progress bars and image carousels.
In short, almost any possible display you have seen on an administrative dashboard is likely included here or in the supported shinydashboard package.
CRAN rank 1,146 out of 20,078 (3rd most downloaded)
Development since 2018 through 2020
Find the project at https://github.com/RinteRface/shinydashboardPlus
Complexity of framework – low
Develop outstanding R shiny app dashboards for iPhone, iPad, Android devices and the desktop. shinyMobile is built with the latest Framework7 template.
shinyMobile has many great features. Native iOS and Android app frameworks. Mobile app capabilities designed from the ground up to work very well on small screens. Cutting-edge web components that rival professional websites with that “wow” factor. In particular, smart support for mobile friendly inputs and controls.
While this is my favorite framework for what you can achieve, the level of difficulty is high, which I why I put it in a close 2nd to shinydashboardPlus.
CRAN rank: 5,595 out of 20,078 (8th most downloaded)
Development since 2016 through 2020
Find the project at https://github.com/RinteRface/shinyMobile/
Complexity of framework – high
Those are my top 3 choices, but here are five more great frameworks and extensions to frameworks for building professional quality dashboards with R shiny apps in 2021.
Build slick R shiny app dashboards with the combination of the Bootstrap 4 framework by Twitter combined with the Argon design system by Creative Tim. Argon has over 100 individual components that are highly customizable. A massive range of web elements is implemented out of the box in Argon. Every web control element has granular specs for colors, styles, hover, focus and more that you can easily access and customize.
Argon is a highly interactive, very clean framework with the “wow” factor, which is why I place it at the top of this list for R shiny app dashboards in 2021.
CRAN rank: 1,782 out of 20,078 (4th most downloaded)
Development since 2018 through 2020
Find the project at https://github.com/RinteRface/argonDash
Complexity of framework – Medium
shinymaterial has less “wow factor” and a more minimalist feel out of the box. A strength is active visual feedback as people interact with controls on the page.
semantic.dashboard offers functions for creating dashboards with a crisp, science journal look and feel. It is based on Fomantic UI, a community fork of Semantic-UI, one of the most popular web frameworks of the last decade with 50,000 GitHub stars.
This is the most widely used package for R shiny app dashboards. It is also the package that has been in development the longest in this list.
CRAN rank 446 out of 20,078 (most downloaded on this list)
Development since 2015 through 2020
Find the project at http://rstudio.github.io/shinydashboard/
Complexity of framework – low
dashboardthemes is an easy but powerful way to fully customize shinydashboard-built R shiny app dashboards. It enhances the shinydashboard framework with easy creation of themes and logos, without knowledge of CSS code. Adds the ability to allow users of your R shiny app dashboards to switch themes within the app.
CRAN rank 1,782 out of 20,078 (5th most downloaded)
Development since 2018 through 2020
Find the project at https://github.com/nik01010/dashboardthemes
Complexity of framework – low
I like to focus more on data analysis rather the technical details of charts. For that reason, although the “grammar of graphics” in ggplot2 is an ingenious system, I rarely use it. It’s more about the graph and less about the analysis.
Keep in mind, ggplot2 is likely the most widely used graph package in R, so it has a huge following in the R community. You can build stunning data visualizations with this package, but with quite complex code. There is an abundance of examples and tutorials online for this package.
I attended an R conference years ago at UCLA and was impressed with the ggvis package in a presentation by Hadley Wickham. ggvis was a grammar of graphics approach to the Vega JS framework (which is a smart layer on top of D3) and had some great interactivity possibilities, including graphic rendering in the browser. However, ggvis was experimental at the time and never quite made it to a production release. As a result, I held off on using it in client projects.
Along the way, I discovered several specialized data visualization packages that are excellent, such as dygraphs by JJ Allaire, the founder of RStudio, and the leaflet package for mapping. Both of these are fairly technical to use for a variety of reasons. Regardless, I use them in client projects, and am happy with the results.
After examining the supporting R package by John Coene of Geneva, I was impressed by the possibilities! It’s an open-source project with 50,000 stars on GitHub (!) built around a mature charting library that is concise and analytical. John Coene has made it very accessible with fairly short code snippets capable of creating great data visualizations. Most important to me, the chart defaults are quite good, and the code is much more concise to achieve good results. All while offering extensive customization options, if you choose to put in the extra effort.
So, as a result of this research, this section is built around just a few packages – echarts4r, leaflet, DT and gt. Since the best description of a package is typically the source, I’ve included quotes from the websites of the creators.
ECharts underpins echarts4r, which provides “… more than 20 chart types available out of the box, along with a dozen components, and each of them can be arbitrarily combined to use. Easily switch between Canvas and SVG rendering. Progressive rendering and stream loading make it possible to render 10 million data in real-time. The default design follows visualization principles, supports responsive design. Flexible configurations make it easy to customize. Automatically generated chart descriptions and decal patterns help users with disabilities understand the content and the stories behind the charts.”
gt allows you to “… make wonderful-looking tables using the R programming language. The gt philosophy: we can construct a wide variety of useful tables with a cohesive set of table parts. These include the table header, the stub, the column labels and spanner column labels, the table body, and the table footer.” The gt package is an abstraction of the grammar of graphics, but for tables. This approach works well with summary table creation in detailed layout and formatting.
DT handles standard tabular formats quite well, but I recommend gt when you require total control over table layout and appearance. Basically, the R gt package is suited to highly formatted, compact tables for critical summaries. The R DT package is appropriate for detailed reviews of large data tables in an interactive, multi-page, user-filterable format.
Want to see these packages in action? Keep reading for examples of essential graph types showcased in an R shiny app on ConnectR, by the YakData team.
If you would like to quickly compare a single metric or data item across multiple categories, use a bar chart or bar graph. The value of the metric is represented by the height or length of the bar.
Perhaps you would like to quickly compare a few categories to gain a rough sense of which categories are larger and smaller relative to the combined total for all categories, often called “percentage of the whole” or relative contribution. If the exact numbers are not important, pie charts are a commonly used alternative.
If you would like to compare actual values between primary groups, as well as actual values of the secondary grouping within each primary group, use a stacked bar chart.
If you would like to investigate how a data item or multiple data items changed over a period of time, use a line chart. These are also referred to as a growth rate chart or time series.
If location is crucial to the problem that you are investigating, display your key metrics on maps. Maps also provide a wow factor and excite your audience.
There are numerous other chart types available with echarts4r. Some of my favorite examples are shown in the gallery below. Visit John Coene’s website, the developer of echarts4r, for these and many more examples, by category: charts, Web GL, statistical charts, maps and geospatial.
Before you improve performance, you’re better off focusing on creating an appropriate and useful R shiny app dashboard FIRST. Utilize analysis and data presentation methods that clearly answer the questions the dashboard audience finds most important. In your first release of a dashboard, IF the answers are valuable, users will have patience for sub-optimal speed and imperfect visualizations.
Once you have a dashboard that gives the audience the core of what they need to make better decisions, then you can spend time enhancing and perhaps perfecting it! This may be before or after you publish an R shiny app dashboard for production use.
Once you’re certain that you have quality data, solid analytics and great data presentation views, you can then make your valuable R shiny app dashboard truly epic with tips from this chapter.
Now, here are some high-value ways to optimize your R shiny app dashboard experience in 2021.
Incorporating data collapse and caching can mean the audience of your dashboard waits only 1 second instead of 30 seconds for an update, for example.
To determine how to do this, ask yourself three questions:
1. What is the minimal data source needed for your dashboard? For instance, can you use only 5 of the source data columns and a summarized format, yet still display what your users need?
2. Can you delay a complete pull of the detailed data until a user clicks on a specific data table view?
3. If you are using a database, are you pushing data collapse/aggregation/column reduction at the earliest part of the data delivery cycle?
One solution I frequently rely upon is the feather package. It provides a very fast, local file storage format for data caching. It is originally from the Apache Arrow project. My experience is that a feather data source versus a CSV or database source can be 2-10X faster to open/requery, depending on the circumstances.
Likewise, reducing the data source size via column selection (select statements in dplyr or even earlier in the data collection cycle) or pre-aggregation can accelerate data access time by another 2-10X.
Note that feather is NOT intended as a long-term storage mechanism, but rather as a data caching format. It is very similar to how memory is kept live on your server computer.
Here is an illustration of data access and caching with feather.
Examples of what you can do with shinyjs include:
+ Hide or show an element on the page.
+ Disable or enable inputs.
+ Change/restore the value of an input.
+ Delay code execution.
One last consideration is building shiny apps with external HTML templates. Dean Attali has instructions on using shinyjs in this configuration. This can be quite time-consuming but allows the embedding of shiny capabilities with your web development standards.
By embedding your R shiny app dashboard as part of larger web development projects, amazing concepts can be achieved from a user workflow, data-sharing and dynamic feedback perspective in complex web/data/organizational environments. I have integrated R shiny apps with Vue.js web platforms using the HTML template approach. The results were indeed impressive. React JS and AngularJS integration/working in parallel with R shiny app dashboards is also possible.
So, let’s get that R shiny app dashboard out there and start getting value and feedback from our users! Here are some of the best ways to publish and share R shiny app dashboards.
1. RStudio Desktop
Note that this option is impractical unless you have a coordinated team of RStudio users, who only need access to the R shiny app dashboard when they can access their computer AND the network on which the data resides AND can keep their package environments in synch.
2. Open source Shiny Server
Open source Shiny Server makes R shiny apps available online. The downsides? Your team installs and maintains the server and server software. Most importantly, no security is implemented to manage access to the published shiny apps. So anyone with the network address to the server can browse and run any app on it.
This is a great option for apps that you wish to make public or put inside your internal firewall for the entire organization to share.
3. RStudio shinyapps.io
Share your shiny applications online in minutes. A cloud-deployed, user-ready alternative with an hour-based metering system for app usage. When your app runs, it runs on a dynamically deployed AWS server and continues running for 15 minutes past the last user request. This is roughly how hours used are calculated.
From a free plan without user security to multiple higher-end secured plans, this is a good option for projects. One of the main restrictions versus other options in this list is a lack of persistent data storage on the server.
4. YakData ConnectR
Publish R shiny apps on ConnectR with secured access for specific users or groups. Colleagues log in using their favorite web browser and open the app to view and interact with their data. R Markdown documents are also supported, including flexdashboard.
Create, edit, test and debug R shiny apps with ConnectR Editor, a secured version of the most popular open source editor for R. Easily upload existing R shiny apps via the Secure FTP server. More than 2,000 of the most popular R packages are pre-installed on ConnectR. Need other packages? You can install them from MRAN, CRAN, GitHub or uploaded files. Upload and download file-based data sources via the SFTP server and define remote data sources with specialized R packages.
Launch your R shiny app project today in minutes from one of 14 locations worldwide and eliminate the hassle of maintenance and upgrades with a hosted ConnectR. Experience high frequency compute performance with ultra-fast on-server storage. Data consumers and data expert teams can get back to making the most of your analysis on ConnectR. No worries about vendor lock-in as your R shiny apps published on ConnectR can be migrated to several open source and proprietary alternatives.
Built by the same team and upon open source Shiny Server, this option appears to have merged into RStudio Connect. The old web page no longer has any content beyond a logo.
6. Shiny Proxy
Deploy Shiny apps in an enterprise context. It has built-in functionality for LDAP authentication and authorization. Your team installs and maintains the server and server software.
It is integrated with the RStudio IDE and allows scheduled execution of content in a secured environment. Your team installs and maintains the server and server software.
Here’s an outline of my lessons learned for building great dashboards.
1. What is the overall purpose?
2. Understand specific business goals
3. Identify the minimum data elements required
4. Tips for dashboards that are:
+ Strategic in nature, and
+ Analytical or tactical in nature
Here is a compact version of some of the methodology I have learned building dashboards over the past two decades. First, there is “no one size fits all” set of rules. There is an incredibly diverse world of possible dashboard applications, but this rough collection of hard-learned tips should help you vastly improve dashboard success in your organization.
Typically, at this stage, you were approached by a manager or colleague with a request to build a dashboard. Alternatively, you may have come up with the idea on your own if you recognized an opportunity to help the business move forward using data.
Before you even start building your dashboard, the question you should ask yourself is
“Why this dashboard?”
Write down 1-3 general questions. Engage with your colleagues to discuss and synthesize concise answers.
After you figure out the core purpose of your dashboard, compile the specific business goals that your team seeks to accomplish. Reading reports that are currently in use is a good source of information. Speaking with top users of these reports to understand what they do with them can be surprising and good guidance for data analyses that will be most useful to dashboard consumers.
Match these goals to key questions and which data would best answer them. I suggest that you initially ignore the data you’ve always used or have conveniently available to you and be open to the possibility of obtaining new data that you haven’t thought of before. Sometimes it’s easier to get than you think! These findings can be the difference between popular and rarely used dashboards.
Now try to pair the questions the dashboard must answer with the most critical data elements required to answer them. Including only what is necessary simplifies all aspects of building, maintain and utilizing the dashboard. You can always add and enrich the data for a popular dashboard, but if you miss the mark with early versions, no one will care if you have a huge range of data display/data analysis options.
If there is crucial data that is missing, sketch out a rough plan to capture and incorporate these data sources over time. Verify these once again with expert users of these data sources in your organization.
Strategic dashboards help your dashboard audience plan for the long-term operation of the business. For this audience, simple is frequently better.
Of course, the definition of “simple” varies by audience! Colleagues will typically look at these dashboards every few weeks or months. These should be easy to interpret, so stick with clear messages and simpler data visualization methods. Ensure that your dashboard aligns what you show with strategic priorities set by top-level leadership in your organization.
For clarity, it can be useful to show targets or simple trends. The chart types that tend to work best here are bar charts, line charts or bullet graphs. Limit interactivity, usually to clearly identifiable filters, and consider adding automated filtering based on the user interacting with the dashboard (e.g., worldwide executive viewing the dashboard versus the European executive viewing the dashboard.)
In a strategic dashboard, slower query times are unacceptable, so schedule or aggregate data as needed. Daily or weekly data pulls and pre-aggregation typically work for strategic dashboard audiences.
Dashboards built for analytic or tactical reasons are often of a higher complexity compared to strategic ones. These are used daily or weekly by people dedicated to certain roles in an organization, such as marketing ads analyst, financial analysts, logistics planners or engineering teams.
Analytic dashboards can incorporate a greater range of metrics and higher levels of anticipated user interactivity, including user willingness to use interactive chart/data table features that aren’t readily apparent to the casual user.
The ability to drill-down on the data for detailed exploration is critical for this class of dashboard. It is important that analysts be able to launch ad-hoc analysis from the dashboard. So consider a data download/data connection option for end-users – possibly at the aggregate level in the dashboard and ideally at the original data feed level.
With analytic dashboards, slower query times may be acceptable, but are obviously not desirable. Due to the exploratory nature that users require in these dashboards, there may be fewer data aggregation opportunities to enhance performance, but there are likely still some areas for optimization after the first dashboard version is released.