<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/enterprise-dashboards-with-r-markdown/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://rviews.rstudio.com/2018/05/16/replacing-excel-reports-with-r-markdown-and-shiny/"> R Views</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><em>This is a second post in a series on enterprise dashboards. See our previous post, <a rel="nofollow" href="https://rviews.rstudio.com/2017/09/20/dashboards-with-r-and-databases/" target="_blank">Enterprise-ready dashboards with Shiny Databases</a>.</em></p>
<p>We have been living with spreadsheets for so long that most office workers think it is obvious that spreadsheets generated with programs like <a rel="nofollow" href="https://products.office.com/en-us/excel" target="_blank">Microsoft Excel</a> make it easy to understand data and communicate insights. Everyone in a business, from the newest intern to the CEO, has had some experience with spreadsheets. But using Excel as the de facto analytic standard is problematic. Relying exclusively on Excel produces environments where it is almost impossible to organize and maintain efficient operational workflows. In addition to fostering low productivity, organizations risk profits and reputations in an age where insightful analyses and process control translate to a competitive advantage. Most organizations want better control over accessing, distributing, and processing data. You can use the R programming language, along with with R Markdown reports and RStudio Connect, to build enterprise dashboards that are robust, secure, and manageable.</p>
<div>
<img src="https://i0.wp.com/rviews.rstudio.com/post/2018-05-16-replacing-excel-with-r-markdown-and-shiny/tracker-excel.png?w=400&ssl=1" data-recalc-dims="1">
</div>
<p>This Excel dashboard attempts to function as a real application by allowing its users to filter and visualize key metrics about customers. It took dozens of hours to build. The intent was to hand off maintenance to someone else, but the dashboard was so complex that the author was forced to maintain it. Every week, the author copied data from an ETL tool and pasted it into the workbook, spot checked a few cells, and then emailed the entire workbook to a distribution list. Everyone on the distribution list got a new copy in their inbox every week. There were no security controls around data management or data access. Anyone with the report could modify its contents. The update process often broke the brittle cell dependencies; or worse, discrepancies between weeks passed unnoticed. It was almost impossible to guarantee the integrity of each weekly report.</p>
<div>
<h3>Why coding is important</h3>
<p>Excel workbooks are hard to maintain, collaborate on, and debug because they are not reproducible. The content of every cell and the design of every chart is set without ever recording the author’s actions. There is no simple way to recreate an Excel workbook because there is no recipe (i.e., set of instructions) that describes how it was made. Because Excel workbooks lack a recipe, they tend to be hard to maintain and prone to errors. It takes care, vigilance, and subject-matter knowledge to maintain a complex Excel workbook. Even then, human errors abound and changes require a lot of effort.</p>
<p>A better approach is to write code. There are many <a rel="nofollow" href="https://twitter.com/MaartenvSmeden/status/995791001825431552" target="_blank">reasons to start programming</a>. When you create a recipe with code, anyone can reproduce your work (including your future self). The act of coding implicitly invites others to collaborate with you. You can systematically validate and debug your code. All of these things lead to better code over time. Coding in R has particular advantages given its vast ecosystem of packages, its vibrant community, and its powerful tool chain.</p>
</div>
<div>
<h3>Using R Markdown</h3>
<p>There are many tools for replacing complex Excel dashboards with R code. One of these tools is <a rel="nofollow" href="https://rmarkdown.rstudio.com/" target="_blank">R Markdown</a>, an open-source R package that turns your analyses into high quality documents, reports, presentations and dashboards. R Markdown documents are fully reproducible and support dozens of output formats including HTML, PDF, and Microsoft Word documents.</p>
<div>
<img src="https://i0.wp.com/rviews.rstudio.com/post/2018-05-16-replacing-excel-with-r-markdown-and-shiny/tracker-rmd.png?w=400&ssl=1" data-recalc-dims="1">
</div>
<p><a rel="nofollow" href="http://colorado.rstudio.com/rsc/tracker-report/tracker-report.html" target="_blank">Here</a> is the same Excel dashboard translated to an R Markdown report. Because this report is written in code, it is vastly simpler and easier to maintain. Like the Excel dashboard above, this R Markdown report is designed to take user inputs so that it could render custom report versions.</p>
<p>Many people are already aware that R Markdown reports combine narrative, code, and output in a single document. What is less commonly known is that you can generalize any R Markdown report by declaring parameters in the document header. R Markdown documents with parameters are known as <a rel="nofollow" href="https://rmarkdown.rstudio.com/developer_parameterized_reports.html" target="_blank">parameterized reports</a>. In the Excel dashboard users can select <code>segment</code>, <code>group</code>, and <code>period</code>. In a parameterized R Markdown document, you would specify these inputs with the following YAML header:</p>
<pre><code>---
title: Customer Tracker Report
output: html_notebook
params:
  seg: 
    label: &quot;Segment:&quot;
    value: Total
    input: select
    choices: [Total, Heavy, Mainstream, Focus1, Focus2, 
              Specialty, Diverse1, Diverse2, Other, New]
  grp: 
    label: &quot;Group:&quot;
    value: Total
    input: select
    choices: [Total, Core, Extra]
  per: 
    label: &quot;Period:&quot;
    value: Week
    input: radio
    choices: [Week, YTD]
---</code></pre>
<p>You can then call the parameters you declare in the YAML header from your R code chunks.</p>
<pre><code>```{r}
params$segment
params$grp
params$per
```</code></pre>
<p>You can render the document with different inputs by selecting <a rel="nofollow" href="https://rmarkdown.rstudio.com/developer_parameterized_reports.html#parameter_user_interfaces" target="_blank">knit with parameters</a> in RStudio. This option will open a user interface that allows you to select the parameters you want.</p>
<div>
<img src="https://i0.wp.com/media.giphy.com/media/vwicMYfRPL6YuRQGfo/giphy.gif?w=456&ssl=1" data-recalc-dims="1">
</div>
<p>If you want to automate the process of creating custom report versions, you can render these documents programmatically with the <code>rmarkdown::render()</code> function.</p>
<pre><code>rmarkdown::render(
  input = &quot;tracker-report.Rmd&quot;, 
  params = list(seg = &quot;Focus1&quot;, grp = &quot;Core&quot;, per = &quot;Weekly&quot;)
)</code></pre>
</div>
<div>
<h3>Publishing to RStudio Connect</h3>
<p>Managing access and permissions for an ocean of Excel files is painful. Data in Excel spreads through an organization without controls like a virus spreads through a body without disease prevention. There are better ways to secure the operation, access, and distribution of information.</p>
<div>
<img src="https://i2.wp.com/media.giphy.com/media/9M52kMrLHrDfxI3nrq/giphy.gif?w=456&ssl=1" data-recalc-dims="1">
</div>
<div>
<img src="https://i1.wp.com/rviews.rstudio.com/post/2018-05-16-replacing-excel-with-r-markdown-and-shiny/pb-publishing.png?w=50&ssl=1" data-recalc-dims="1">
</div>
<p>RStudio Connect is a server product from RStudio that is designed for secure sharing of R content. It is on-premises software you run behind your firewall. You keep control of your data and of who has access. With RStudio Connect, you can see all your content, decide who should be able to view and collaborate on it, tune performance, schedule updates, and view logs. You can schedule your R Markdown reports to run automatically or even distribute the latest version by email.</p>
<p>When you publish a parameterized R Markdown report to RStudio Connect, an interface appears for selecting inputs. Viewers can create new report versions, then email themselves a copy. Collaborators can save and schedule new report versions, then email others a copy. You can even attach <a rel="nofollow" href="http://docs.rstudio.com/connect/1.6.2/user/r-markdown.html#r-markdown-output-files" target="_blank">output files</a> to these versions. Using parameterized R Markdown documents in RStudio Connect is a powerful way to communicate information.</p>
<p>You can publish content from the RStudio IDE by clicking the <a rel="nofollow" href="https://support.rstudio.com/hc/en-us/articles/228270928-Push-button-publishing-to-RStudio-Connect" target="_blank">Publish button</a> that looks like a blue Eye of Horus. Pressing this button will begin the publishing process. First, it creates a set of instructions for recreating your content. Second, it deploys your content bundle to the server. Third, it recreates your content on RStudio Connect. Push-button publishing has a long history of being used with RStudio. In 2012, RStudio enabled push-button publishing of R Markdown documents to <a rel="nofollow" href="https://rpubs.com/" target="_blank">RPubs</a>. In 2014, RStudio enabled push-button publishing of Shiny apps to <a rel="nofollow" href="http://www.shinyapps.io/" target="_blank">shinyapps.io</a>. In 2016, RStudio enabled push-button publishing to <a rel="nofollow" href="https://www.rstudio.com/products/connect/" target="_blank">RStudio Connect</a>.</p>
</div>
<div>
<h3>Adding Shiny</h3>
<p>R Markdown documents are rendered with batch processing. That makes them ideal for automation, long running workflows, and custom report versions. However, if you want your documents to be immediately reactive to user input, then you can add a Shiny runtime. These <a rel="nofollow" href="https://rmarkdown.rstudio.com/authoring_shiny.html" target="_blank">interactive documents</a> behave like a Shiny application in that they must be hosted. You can host <a rel="nofollow" href="https://rmarkdown.rstudio.com/authoring_shiny.html" target="_blank">interactive documents</a> and <a rel="nofollow" href="http://shiny.rstudio.com/" target="_blank">Shiny applications</a> with RStudio Connect. Deciding when to choose between R Markdown, interactive documents, and Shiny applications is a subject for a later post.</p>
</div>
<div>
<h3>Summary</h3>
<p>Reproducible code in R leads to better analysis and collaboration. You can use parameterized R Markdown reports to create complex, interactive dashboards. Hosting these dashboards securely in RStudio Connect gives you control over accessing, distributing, and processing data. You can use the R programming language, along with with R Markdown reports and RStudio Connect, to build enterprise dashboards that are robust, secure, and manageable.</p>
<p><em>Click <a rel="nofollow" href="https://github.com/sol-eng/customer-tracker" target="_blank">here</a> for source code.</em></p>
</div>
<p> </p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://rviews.rstudio.com/2018/05/16/replacing-excel-reports-with-r-markdown-and-shiny/"> R Views</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/t8dcabmgwe0" height="1"></a></div>