<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/prettify-your-shiny-tables-with-dt-exercises/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://www.r-exercises.com/2018/10/08/prettify-your-shiny-tables-with-dt-exercises/"> R-exercises</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p><a rel="nofollow" href="https://i0.wp.com/www.r-exercises.com/wp-content/uploads/2018/08/spreadsheet-147749_1280.png?ssl=1" target="_blank"><img sizes="(max-width: 300px) 100vw, 300px" src="https://i1.wp.com/www.r-exercises.com/wp-content/uploads/2018/08/spreadsheet-147749_1280-300x298.png?resize=300%2C298&ssl=1" alt="" width="300" class="wp-image-11927" data-recalc-dims="1" height="298"></a>Have you ever wanted to make your Shiny tables interactive, more functional and look better? The DT package, which stands for “DataTables”, provides an R interface to the JavaScript library “DataTables”. It allows creating high standard tables by implementing the functionalities and design features that are available through the “DataTables” library.</p>
<p>Even though the DT package can be used independently of Shiny, this exercise set will focus on the integration between the two packages. The exercises were built with a practical orientation in mind, and upon completing them you would be ready to tackle the vast majority of use cases for using DT with Shiny.</p>
<p>We will work with the light built-in dataset <code>datasets::Orange</code>, that holds data about growth of orange trees. Each exercise is adding some more features/functionalities to the code of the previous exercise, so be sure to not discard the code until after you’re done with all of the exercises. Answers to the exercises are available <a rel="nofollow" href="https://r-exercises.com/2018/10/08/prettify-your-shiny-tables-with-dt-solutions/" target="_blank">here</a>.</p>
<p>Each exercises should result in a Shiny app, where the changing part is the <code>renderDataTable()</code> function.<br>
To save time, you can use the following template, and just replace the placeholder for each exercise.<br>
<code><br>
ui &lt;- fluidPage(<br>
br(), br(), br(),<br>
fluidRow(column(width = 6, DT::dataTableOutput(outputId = &quot;my_datatable&quot;)))<br>
)</code></p>
<p>server &lt;-function(input, output, session) {<br>
output$my_datatable &lt;-<br>
}</p>
<p>shinyApp(ui = ui, server = server)</p>
<p><strong>Exercise 1</strong><br>
Generate a minimal Shiny app that displays the dataset <code>Orange</code> in a datatable (default values).</p>
<p><strong>Exercise 2</strong><br>
Remove the row names.</p>
<p><strong>Exercise 3</strong><br>
Show only 7 rows as the default display, and allow changing the number of displayed rows to either 14, 21, 28 or 35.</p>
<p><strong>Exercise 4</strong><br>
Align the columns text (both values and headers) to the center.</p>
<p><strong>Exercise 5</strong><br>
Remove the search box (top right) and the table information text (bottom left).</p>
<div>
<aside><img src="https://www.r-exercises.com/2018/10/08/prettify-your-shiny-tables-with-dt-exercises/"></aside>
<div><strong>Learn more</strong> about Shiny apps in the online courses <a rel="nofollow" href="https://www.r-exercises.com/product/r-shiny-apps/" target="_blank">Create Interactive Web Applications with the R Shiny Package</a> and <a rel="nofollow" href="https://www.r-exercises.com/product/r-shiny-interactive-web-apps/" target="_blank">R Shiny Interactive Web Apps</a>.</div>
</div>
<p><strong>Exercise 6</strong><br>
Add a “copy” and “csv” buttons to allow saving the table to the clipboard and downloading it as a CSV respectively.</p>
<p><strong>Exercise 7</strong><br>
Add a filter box for each column, at the bottom of the table.</p>
<p><strong>Exercise 8</strong><br>
Allow selection of a single row only, rather than multiple rows (which is the default).</p>
<p><strong>Exercise 9</strong><br>
Remove the option to sort the table.</p>
<p><strong>Exercise 10</strong><br>
Finally, if a row was selected, display in the UI (<code>textOutput</code>) the selected <code>tree</code> and <code>age</code> values.<br>
Hint: for this exercise you would have to make additional changes to the UI and server, rather than just changing the <code>renderDataTable()</code> function.</p>
<div>
<h3>Related exercise sets:</h3>
<ol>
<li><a rel="nofollow" href="https://www.r-exercises.com/2017/07/13/parallel-computing-exercises-foreach-and-doparallel-part-2/" title="Parallel Computing Exercises: Foreach and DoParallel (Part-2)" target="_blank">Parallel Computing Exercises: Foreach and DoParallel (Part-2) </a></li>
<li><a rel="nofollow" href="https://www.r-exercises.com/2017/08/03/parallel-computing-exercises-snow-and-rmpi-part-3/" title="Parallel Computing Exercises: Snow and Rmpi (Part-3)" target="_blank">Parallel Computing Exercises: Snow and Rmpi (Part-3) </a></li>
<li><a rel="nofollow" href="https://www.r-exercises.com/2018/02/11/bayesian-inference-mcmc-diagnostics-using-coda/" title="Bayesian Inference – MCMC Diagnostics using coda : Exercises" target="_blank">Bayesian Inference – MCMC Diagnostics using coda : Exercises </a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/start-here-to-learn-r/" target="_blank">Explore all our (>1000) R exercises</a></li>
<li><a rel="nofollow" href="http://www.r-exercises.com/r-courses/" target="_blank">Find an R course using our R Course Finder</a> directory</li>
</ol>
</div>
	<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://www.r-exercises.com/2018/10/08/prettify-your-shiny-tables-with-dt-exercises/"> R-exercises</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/ATtJ17CeHZM" height="1"></a></div>