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:
Let’s dive right in.
New to R shiny apps? Start in this section.
An expert? You know that you can always pick up a few new tricks!
Building a quality R shiny app is core to EVERYTHING you do in crafting professional quality R shiny app dashboards.
And in this first step, I’m going to share with you how to create awesome R shiny apps for your team.
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’s cloud servers
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 cloud servers, 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’s cloud servers. This example app uses one of the advanced dashboard frameworks, so it is 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 visualizes 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’s cloud servers.
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.
How to Make a Professional-looking Shiny App and Not Get Intimidated (With R) by Lathan Liou.
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 Gromelund at RStudio.
So at this point, you should have a solid R shiny app.
And you’re probably wondering: “How do I know which R shiny app dashboard framework to pick?”.
Well, there’s no magic formula that’s going to show you the perfect framework.
But there ARE pros and cons to each framework that you should understand to effectively choose the best R shiny app dashboard framework for your project needs.
That’s exactly what I’m going to cover in this section.
Framework | CRAN Rank | Relative Download Rank | Years Under Development | Responsive sizing | Complexity to Use |
---|---|---|---|---|---|
shinydashboardPlus | 1146 | 3rd | 2018-2020 | Yes | Low |
shinyMobile | 5595 | 8th | 2016-2020 | Yes | High |
flexdashboard | 768 | 2nd | 2016-2020 | Somewhat | High |
argonDash | 1782 | 4th | 2018-2020 | Yes | Medium |
shinymaterial | 3532 | 7th | 2017-2020 | Yes | Medium |
semantic.dashboard | 2860 | 6th | 2017-2020 | Yes | Low |
shinydashboard | 446 | 1st | 2015-2020 | Yes | Low |
dashboardthemes | 1782 | 5th | 2018-2020 | Yes | Low |
Avoid tables if you don’t require exact values or detailed precision – they can be difficult and time-consuming to read and interpret.
Use only the metrics you need – too many will clutter the table.
Tables for detailed, interactive review: DT.
Tables as a highly formatted, compact summaries: gt.
If you are highlighting transactions with errors so that you remember to investigate them, color the cells red when they don’t match, and green when they’re okay – the further off the correct value, the brighter red the color.
Keep in mind that about 5% of Americans are color blind, so if there’s a good chance you may be showing your chart to one of them, use shading or a color-blind palette instead.
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.
If each group has many and/or long labels, a vertical bar chart is often superior. I especially prefer them when ranking is the purpose of the chart.
If ranking is key, sort according to the metric of interest.
Always include the zero-axis (start at the zero value) for any type of bar chart. If you don’t, the graph will not accurately depict the data, because it will make the differences between the bars look larger than they are.
If you have many bars in each pane, consider showing just the top 10 or 20 items by grouping the remaining items into an “Other” category.
Resist the temptation to use different colors or shading for each bar unless the colors mean something important. Your audience will be distracted by the colors when they have no particular meaning, directing them away from the overall shape of the data.
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.
Visualization experts have concluded that it is extremely difficult to distinguish the sizes of the slices in pie charts, and they advise against using them. However, they are easy to understand and have been used widely in business for a long time, so they are still a popular graph type in spite of their limitations. Whenever possible, I use bar charts instead of pie charts.
If you have more than 6-8 categories, combine smaller categories into an “Other” slice or use a bar chart.
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.
Only stack sums or counts, not averages. Stacking a bunch of averages is not only confusing, but also misleading.
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.
Show the zero-axis (start at the zero value). Otherwise, the graph may imply a misleading growth rate, by making it appear that there was a lot of growth or shrinkage, when there wasn’t. The exception to this is if the area of interest is volatile or variable.
If the data are highly volatile on a daily basis, instead of showing every data point, average or sum by month for an easier-to-read chart.
If you need to know the amount of something to date rather than just individual values, consider using a running total. Year-to-date (YTD) is a typical one.
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.
Supplement your map by placing relevant data in another chart type. For instance, you may want to display sales for each state in a table below the map.
shinyjs is the preferred way to enhance your R shiny app dashboard with additional interactive capabilities in the browser. shinyjs simplifies the addition of JavaScript/jQuery operations to your dashboard.
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.
+ Run JavaScript code on page load.
+ Create and execute on-demand your own JavaScript functions from the R server function in your shiny app.
A great tutorial to learn the core of shinyjs is at the package author’s website, Dean Attali. An example of advanced user feedback messages is shown below.
Every production R shiny app dashboard that I have developed has used JavaScript enhancements, usually with the use of shinyjs. On occasion, I had simpler needs that could be fulfilled with standard methods to add JavaScript to shiny apps without the addition of the shinyjs package.
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.
Subscribe to our newsletter
Content publishing is a SUPER important part of the R shiny app dashboard lifecycle. Why make it if you don’t share it?
In my experience, most people use the “Publish and Pray” approach to R shiny app dashboards. In other words, they publish a piece of content… and hope that people find value in it.
The truth is that you will likely need to update your dashboard a few times over the first few months. Your view of how to display the data won’t always coincide with the way that your dashboard consumers use the data to answer their questions.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 computes 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.
5. RStudio Shiny Server Pro (now RStudio Connect)
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.
7. RStudio Connect
A publishing platform for Python and R content. You can share shiny apps, R Markdown documents, Plumber APIs and Jupyter Notebooks.
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.
Subscribe to our newsletter