How to Improve Design of R Shiny Dashboard with the semantic.dashboard Package

Estimated time:

<strong>Updated</strong>: April 26, 2022. <code class="highlighter-rouge">semantic.dashboard</code> is an R package used to improve the design of R Shiny dashboards. It's an alternative to <code class="highlighter-rouge">shinydashboard</code> and makes use of Semantic UI. The package allows developers to easily introduce Semantic UI components into R Shiny apps. The package is available on the Comprehensive R Archive Network (CRAN). You can make use of it simply by running <code>install.packages("semantic.dashboard")</code>. You might also be interested in this 2020 <a href="">tutorial</a> on how to build a high-quality Shiny dashboard with the semantic.dashboard package. Table of contents: <ul><li><a href="#improve-design">Improve Design of R Shiny Dashboards with semantic.dashboard</a></li><li><a href="#get-started">How to Get Started with semantic.dashboard?</a></li><li><a href="#add-content">How to Add Content to semantic.dashboard Dashboards</a></li><li><a href="#interactive-terms">Add Interactive Items to R Shiny Dashboards</a></li><li><a href="#source-code">Source Code</a></li><li><a href="#conclusion">Conclusion</a></li></ul> <hr /> <h2 id="improve-design">Improve Design of R Shiny Dashboards with semantic.dashboard</h2> R Shiny is an excellent package for interactive data visualizations. However, fitting a large number of graphs onto just one Shiny page may prove to be a challenge. In our experience, virtually all projects with new KPIs being introduced along the way result in inadequate and not readable final reports.  Dashboards provide a solution. They allow the developer to intuitively structure their reports by breaking them down into sections, panels, and tabs. This makes it much easier for the final user to navigate through the data. <code class="highlighter-rouge">shinydashboard</code> is one available solution and provides decent features. The only problem is - all shinydashboard apps look virtually identical. In this article, we will show you how to take advantage of the semantic.dashboard package. It is an alternative to <code class="highlighter-rouge">shinydashboard</code> which makes use of <a href="" target="_blank" rel="noopener noreferrer">Semantic UI</a>. The package allows developers to introduce attractive Semantic components into the app and select from many available themes. If you don’t have <code class="highlighter-rouge">semantic.dashboard</code> installed yet, visit <a href="" target="_blank" rel="noopener noreferrer">this GitHub page</a> for detailed instructions. As mentioned earlier, the package is available on CRAN, so you can install it directly in RStudio. <h2 id="get-started">How to Get Started with semantic.dashboard?</h2> Let's keep things simple and start by creating an empty dashboard: <script src=""></script> For comparison, you can check what happens if you change <code class="highlighter-rouge">library(semantic.dashboard)</code> to <code class="highlighter-rouge">library(shinydashboard)</code>. The dashboard should look similar to this: <img class="wp-image-8257 size-full" src="" alt="shiny development step 1: empty dashboard" width="593" height="271" /> Image 1 - Empty dashboard &nbsp; With almost no effort we have created the skeleton for our first <code class="highlighter-rouge">semantic.dashboard</code> app. Now it is time to discuss the basic components of a dashboard. Each <code class="highlighter-rouge">dashboardPage</code> consists of three elements: <ul><li>header</li><li>sidebar</li><li>body</li></ul> Currently, our header is quite boring, so let’s add a title and change its color: <script src=""></script> We don’t need a sidebar to be this wide. We also would like to make it more functional, so let’s add two menu elements: <script src=""></script> This is the result we should get: <img class="wp-image-8258 size-full" src="" alt="shiny development step 2: basic dashboard styling" width="383" height="274" /> Image 2 - Basic dashboard styling &nbsp; Not bad! We can do even better by adding some icons to our <code class="highlighter-rouge">menuItem</code>s. Can you do it yourself? (<em>Hint: Use <code class="highlighter-rouge">semantic.dashboard</code> documentation, eg. by typing <code class="highlighter-rouge">?menuItem</code> in RStudio console</em>). <h2 id="add-content">How to Add Content to semantic.dashboard Dashboards</h2> In this section, we will start filling our app with some content. We will use a popular dataset <a href="" target="_blank" rel="noopener noreferrer">“mtcars”</a>, extracted from the 1974 Motor Trend US magazine, which comprises a range of parameters for 32 old-school automobiles. First, we'll need to change the content of the dashboard body using tabs. Look at the following code snippet: <script src=""></script> We created two <code class="highlighter-rouge">tabItem</code>s with <code class="highlighter-rouge">tabName</code>s exactly the same as <code class="highlighter-rouge">menuItem</code>s. The <code class="highlighter-rouge">selected</code> parameters of <code class="highlighter-rouge">tabItems</code> tell us which <code class="highlighter-rouge">tabItem</code> should be selected and displayed after running the app. Equipped with this knowledge, we can implement something functional. We'll start by creating a simple plot describing the relationship between the car’s gearbox type and their miles per gallon parameter. In the <code class="highlighter-rouge">shinyServer</code> function, we call: <script src=""></script> Since we are using <code class="highlighter-rouge">ggplot2</code> do not forget to import it at the beginning of the script. We are going to make another plot from this dataset, so let’s divide the main page into two sections. We can exchange content of <code class="highlighter-rouge">fluidRow</code> function of our first <code class="highlighter-rouge">tabItem</code> by: <script src=""></script> This is a good moment to make sure that your app is running. If the answer is yes, proceed to the next section. In case it’s not, verify if you followed all the previous steps. <h2 id="interactive-terms">Add Interactive Items to R Shiny Dashboards</h2> To add a more interactive plot to our dashboards we can use <a href="" target="_blank" rel="noopener noreferrer">“plotly”</a> R package. In this example, we will use it to present the relation between the weight of a car and miles per gallon. We decided on a scatter plot since it can provide additional information. We marked the number of cylinders by color and the quarter-mile time by the size of the points: <script src=""></script> Note that we used <code class="highlighter-rouge">semantic_palette</code> here for graph colors in order to stay consistent with the SemanticUI layout of the app: <script src=""></script> Here's what the dashboard looks like after the change: <img class="wp-image-8259 size-full" src="" alt="shiny development step 3: sample interactive plots" width="1100" height="547" /> Image 3 - Sample interactive plots We can now move on to the next tab to provide the user with additional information. For instance, we can add a complete list of cars properties in the “Extra” tab for the curious automobile enthusiast. To do so, we'll use the <code class="highlighter-rouge">DT</code> package to render the table on the server-side: <script src=""></script> And now display it on the second tab: <script src=""></script> <img class="wp-image-8260 size-full" src="" alt="shiny development step 4: sample table view" width="947" height="454" /> Image 4 - Sample table view The dashboard looks pretty good by this point. But let's change the visuals by altering the dashboard theme. You can find a list of available themes on the <a href="" target="_blank" rel="noopener noreferrer">Semantic Forest</a> website - the <code class="highlighter-rouge">cerulean</code> theme will do the trick. It is simple to change the theme now, as it requires changing just one parameter in the <code class="highlighter-rouge">dashboardPage</code> function. <script src=""></script> Here's what the dashboard looks like after the change. <img class="wp-image-8261 size-full" src="" alt="sample shiny dashboard demo" width="1302" height="619" /> Image 5 - Sample Shiny dashboard demo <h2 id="source-code">S0urce code</h2> If you missed a step or two, you can review the complete code for the dashboard below: <script src=""></script> <hr /> <h2 id="conclusion">Summary of semantic.dashboard for Improving Design of R Shiny Dashboards</h2> Today you've learned how to improve the design of R Shiny dashboards with the semantic.dashboard package. It's really easy to use, as you had the chance to see, and it will enable you to produce great-looking visuals in less time.  For the homework, we encourage you to customize the dashboard by adding more tabs with new interactive plots. If you’re looking to build your first R Shiny dashboard, you can use <a href="" rel="noopener noreferrer">Appsilon Shiny Dashboard Templates</a> to simplify the process. The bundle contains a ton of beautiful and easy-to-use templates. The best part – is it’s entirely free. In case you need something more advanced, we’re also here to help. <a href="" rel="noopener noreferrer">Appsilon</a> is an <a href="" rel="noopener noreferrer">RStudio Full Service Certified Partner</a>. We develop advanced R Shiny applications for Fortune 500 companies across the globe. We’d be happy to help you choose the right options for your use case. <h3 id="resources">Resources:</h3><ul><li><a href="" target="_blank" rel="noopener noreferrer">semantic.dashboard GitHub page</a></li><li><a href="" target="_blank" rel="noopener noreferrer">shiny.semantic GitHub page</a></li></ul>

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.
Have questions or insights?
Engage with experts, share ideas and take your data journey to the next level!
Join Slack
Explore Possibilities

Take Your Business Further with Custom Data Solutions

Unlock the full potential of your enterprise with our data services, tailored to the unique needs of Fortune 500 companies. Elevate your strategy—connect with us today!

Talk to our Experts
open source
shiny dashboards