1667994420
summarytools is a an R package for data cleaning, exploring, and simple reporting. The package was developed with the following objectives in mind:
On a more personal level, I simply wish to share with the R community and the scientific community at large the functions I first developed for myself, that I ultimately realized would benefit a lot of people who are looking for the same thing I was seeking in the first place.
The bulk of the technical documentation can now be found in the following vignettes:
Introduction to summarytools | CRAN version
Summarytools in R Markdown | CRAN Version
PDF Manual (automatically generated by CRAN)
Additional software is used by summarytools for fine-tuning graphics as well as offering interactive functionality. If you are installing summarytools for the first time, click on the relevant link to get OS-specific instructions. On Windows, no additional software is required.
Mac OS X
Ubuntu / Debian / Mint
Older Ubuntu (14 and 16)
Fedora / Red Hat / CentOS
Solaris
This method has the advantage of benefiting from minor fixes and improvements that are added between CRAN releases. Its main drawback is that you won’t be noticed when a new version is available. You can either check this page from time to time, or best, use a package that checks for package updates on various repositories, such as dtupdate and Drat.
install.packages("remotes") # Using devtools is also possible
library(remotes)
install_github("rapporter/pander") # Strongly recommended
install_github("dcomtois/summarytools", build_vignettes = TRUE)
CRAN versions are stable but are not updated as often as the GitHub versions. On the plus side, they can be easier to install on some systems.
install.packages("summarytools")
Latest Changes
In dfSummary()
:
help("st_options", "summarytools")
for examples)graph.magnif
should resolve itInf
values are handled properlyIn descr()
and ctable()
several display glitches were corrected
Selected heading elements can be totally omitted on an individual basis
Improved functionality for customized terms / translations
For more details, see vignette("introduction", "summarytools")
as well as news(package = "summarytools")
.
Additional Software Installations
Open a terminal window and enter the following:
brew install imagemagick@6
If you do not have brew installed, simply enter this command in the terminal:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
If you’re using Mac OS X version 10.8 (Mountain Lion) or more recent versions, you’ll need to download the .dmg image from xquartz.org and add it to your Applications folder.
Magick++sudo apt install libmagick++-dev
This applies only if you are using Ubuntu Trusty (14.04) or Xenial (16.04).
sudo add-apt-repository -y ppa:opencpu/imagemagick
sudo apt-get update
sudo apt-get install -y libmagick++-dev
Magick++sudo yum install ImageMagick-c++-devel
pkgadd -d http://get.opencsw.org/now
/opt/csw/bin/pkgutil -U
/opt/csw/bin/pkgutil -y -i imagemagick
/usr/sbin/pkgchk -L CSWimagemagick
Author: Dcomtois
Source Code: https://github.com/dcomtois/summarytools
1667507760
Create simple, beautiful personal websites and landing pages using only R Markdown.
You can install Postcards with the following command:
install.packages("postcards")
Or you can install the latest development version:
remotes::install_github("seankross/postcards@main")
Postcards includes five templates: Jolla, Jolla Blue, Trestles, Onofre, and Solana. Each site is optimized for being displayed on desktop and mobile. The goal of the package is to make it easy for anyone to create a single page personal website with one R Markdown document. I hope this package can quickly demonstrate the power and possibilities of the R and R Markdown ecosystem to newcomers.
To get started customizing one of these templates you should create a new project in RStudio. Once you open RStudio: select File, New Project..., then select New Directory, and Postcards Website. Then you will need to enter a directory name for your RStudio project and you can choose one of the templates from a drop down menu. Select Create Project after you choose a name for the folder that will contain your site. This folder will contain two important files: an R Markdown document with your site's content, and a sample photo that you should replace.
If you are not using RStudio or if you do not wish to create a new RStudio project you can create the corresponding template files using the following commands:
postcards::create_postcard(template = "jolla")
postcards::create_postcard(template = "jolla-blue")
postcards::create_postcard(template = "trestles")
postcards::create_postcard(template = "onofre")
postcards::create_postcard(template = "solana")
To compile the self contained HTML file for your site, you can use the Knit button in RStudio or you can use rmarkdown::render("index.Rmd")
. The HTML file can then be easily deployed to GitHub Pages or Netlify Drop.
---
title: "Tobi Burns"
image: "tobi.jpg"
links:
- label: LinkedIn
url: "https://linkedin.com/"
- label: Twitter
url: "https://twitter.com/"
- label: GitHub
url: "https://github.com/"
- label: Email
url: "mailto:email@email.com"
output:
postcards::jolla
---
I am a classically trained data scientist living in the San Francisco Bay Area.
Currently I work on the Oculus team at Facebook. I love talking about baseball,
true crime podcasts, and causal inference.
---
title: "Xiang Guo"
image: "xiang.jpg"
links:
- label: LinkedIn
url: "https://linkedin.com/"
- label: Twitter
url: "https://twitter.com/"
- label: GitHub
url: "https://github.com/"
- label: Email
url: "mailto:email@email.com"
output:
postcards::jolla_blue
---
Raised in New Jersey by two lawyers, I am now an aspiring data artist and
competitive rock climber. I moved to Seattle to fly floatplanes, but I got
caught up in the startup world. Send me a WhatsApp message if you have good
turnip prices.
---
title: "Frank Hermosillo"
image: "frank.jpg"
links:
- label: LinkedIn
url: "https://linkedin.com/"
- label: Twitter
url: "https://twitter.com/"
- label: GitHub
url: "https://github.com/"
- label: Email
url: "mailto:email@email.com"
output:
postcards::trestles
---
## Bio
Frank Hermosillo studies neural networks and their applications at Google
Brain. His research focuses on differentiable network pruning approximation and
decentralized gradient inversion mechanics. He frequently collaborates with
researchers who study machine learning, computer vision, and cognitive science.
His work has been featured in WIRED, The Atlantic, Newsweek, and The New York
Times Magazine.
## Education
**Massachusetts Institute of Technology** | Cambridge, MA
Ph.D. in Computer Science | September 2009 - May 2014
**The University of California, Berkeley** | Berkeley, CA
B.S. in Computer Science | September 2005 - May 2009
## Experience
**Google Brain** | Principal Investigator | January 2018 - Present
**Netflix** | Research Scientist | June 2014 - December 2017
---
title: "Willkommen!"
image: "herzl.jpg"
color1: "#5A59A3"
color2: "#C66060"
angle: 130
links:
- label: YouTube
url: "https://youtube.com/"
- label: Vimeo
url: "https://vimeo.com/"
- label: Twitter
url: "https://twitter.com/"
- label: Email
url: "mailto:email@email.com"
output:
postcards::onofre
---
György Herzl is a filmmaker and computational storyteller based in Leipzig,
Germany. Their work has been featured at the Festival do Rio, Internationale
Filmfestspiele Berlin, Kunsthalle Basel, and the New Museum of Contemporary Art
in New York City. "ГУМ" is their latest project which examines the rise of
consumerism in post-Soviet republics.
---
title: "Sigríður Björndotter"
image: "sigridur.jpg"
links:
- label: Resume
url: "https://linkedin.com/"
- label: Blog
url: "https://medium.com/"
- label: SoundCloud
url: "https://soundcloud.com/"
- label: Twitter
url: "https://twitter.com/"
output:
postcards::solana
---
## Bio
Sigríður Björndotter is a musician, vocalist, and live entertainment consultant
living in Buenos Aires, Argentina. Her writing has appeared in Rolling Stone,
Billboard, and NME, and she is a frequent contributor to National Public Radio's
*All Songs Considered*. She has been raising Pembroke Welsh Corgis since the age
of six, and she has collected Casio watches since the age of ten.
## Education
**INSEAD** | Fontainebleau, France
M.B.A. | August 2014 - June 2015
**The Juilliard School** | New York, NY
B.F.A. in Music Performance | August 2005 - May 2009
## Experience
**Freelance** | Live Entertainment Consultant | August 2018 - Present
**Cercle** | Producer | August 2018 - Present
**National Public Radio** | Producer | May 2015 - July 2018
**NME Magazine** | Editor | July 2014 - July 2016
**Iceland Symphony Orchestra** | Cellist | October 2009 - June 2014
Most issues that people have using this package are related their installation Pandoc, software that R Markdown relies on. Currently Postcards works best with Pandoc version 2.8 or greater, although we are working on better functionality for earlier versions of Pandoc. You can check which version of Pandoc you have installed with the following command:
rmarkdown::pandoc_version()
If you have an earlier version of Pandoc installed we recommend you install the latest version of Pandoc and then run the command:
rmarkdown::find_pandoc(cache = FALSE)
If you do not see that the new Pandoc version has been installed, you may need to use RStudio and install the latest preview release of RStudio. If you are still encountering error messages after trying the above please open an issue.
Please note that the postcards project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.
Author: Seankross
Source Code: https://github.com/seankross/postcards
License: Unknown, MIT licenses found
1667452500
The learnr package makes it easy to turn any R Markdown document into an interactive tutorial. Tutorials consist of content along with interactive components for checking and reinforcing understanding. Tutorials can include any or all of the following:
Narrative, figures, illustrations, and equations.
Code exercises (R code chunks that users can edit and execute directly).
Quiz questions.
Videos (supported services include YouTube and Vimeo).
Interactive Shiny components.
Tutorials automatically preserve work done within them, so if a user works on a few exercises or questions and returns to the tutorial later they can pick up right where they left off.
Learn more about the learnr package and try example tutorials online at https://rstudio.github.io/learnr/.
Install the latest official learnr release from CRAN:
install.packages("learnr")
Or you can install the most recent version in-development from GitHub with the remotes package:
# install.packages("remotes")
remotes::install_github("rstudio/learnr")
learnr works best with a recent version of RStudio (v1.0.136 or later) which includes tools for easily running and previewing tutorials.
Author: View license
Source Code: https://github.com/rstudio/learnr
License: View license
1667378295
Welcome to the GitHub repository page for Statistical Inference via Data Science: A ModernDive into R and the Tidyverse available at ModernDive.com. You can purchase the CRC Press print edition on their website using promo code ADC22 for a discounted price.
ModernDive is built using RStudio's bookdown
package; for more information on how to use bookdown
see bookdown.org. If you'd like to build the book on your own, please make sure to first install the bookdown
package via install.packages("bookdown")
.
bookdown
source code for the current version of the book is in the master
branch of this repo.bookdown
source code for all previously released versions of ModernDive is accessible on the Releases page. A summary of all changes between versions can be found in NEWS.md.gh-pages
branch of this repo.We are also slowly working on a future version of ModernDive:
bookdown
source code for the future version of the book is in the v2
branch of this repo.moderndive
R package.Author: Moderndive
Source Code: https://github.com/moderndive/ModernDive_book
License: View license
1667358360
This R package provides ready-to-use HTML output formats and templates for RMarkdown documents. The goal is to produce clean documents "out of the box", with or without the RStudio IDE.
The package provides several HTML output formats. Click on any image to see an HTML output sample.
downcute
Taken from the docute project theme and its adaptation by John Coene. Responsive, with a dynamic table of contents and a dark theme switcher.
downcute chaos
is a variation created by Zac Garland. It has a slightly different color theme, and defaults to dark mode. To use it, add a downcute_theme: "chaos"
option in your YAML preamble.
robobook
Adapted from the bookdown theme, with Roboto family fonts. Fully responsive with dynamic table of contents and collapsible navigation.
material
Format taken from the Material design theme for Bootstrap 3. Document is split into pages at each <h1>
header, and the table of contents allows an animated navigation between these pages (you can use the cards: false
preamble parameter to disable the splitting and display all the cards at once).
readthedown
Adapted from the corresponding readtheorg
theme of the org-html-themes project, fully responsive with dynamic table of contents and collapsible navigation.
html_clean
Simple and clean template with dynamic table of contents, very similar to the one from the great knitrBootstrap package by Jim Hester.
html_docco
Simple template, no table of contents. CSS heavily inspired from the default one of the docco project.
lockdown
lockdown
is an exact copy of the default RMarkdown html_document
template, with an added functionality : each time you click on a link to get out, you'll see a friendly reminder to wash your hands and wear a mask. Yes, it is a (bad) attempt at a (bad) joke, sorry !
Responsive | Dynamic TOC | Dark mode | Thumbnails / Lightbox | Code folding | Tabsets | Bad joke | |
---|---|---|---|---|---|---|---|
html_docco | x | x | x | x | |||
html_clean | x | x | x | x | x | ||
readthedown | x | x | x | x | |||
material | x | x | x | ||||
robobook | x | x | x | x | x | ||
downcute | x | x | x | x | x | x | |
lockdown | x |
The package also provides RStudio document templates to easily generate an empty and ready to use rmarkdown file with several configuration directives.
It also provides the pilltabs()
helper function, which allows to display a crosstab dynamically. See one of the output samples for a live example.
You can install the latest stable release from CRAN :
install.packages("rmdformats")
Or the latest development snapshot from GitHub :
install.packages(remotes) # if necessary
remotes::install_github("juba/rmdformats")
Just create a new Rmd
file and add the following in your YAML preamble :
---
output: rmdformats::<template name>
---
Within RStudio , you can also choose File
> New File...
> R Markdown...
, then select From Template
. You should then be able to create a new document from one of the package templates.
Depending on the features provided by the template, you can add the following options to your YAML preamble. Look at the template function help page for a valid list :
fig_width
: figures width, in inchesfig_height
: figures height, in inchesfig_caption
: toggle figure caption renderinghighlight
: syntax highlightingthumbnails
: if TRUE, display content images as thumbnailslightbox
: if TRUE, add lightbox effect to content imagesgallery
: if TRUE, add navigation between images when displayed in lightboxuse_bookdown
: if TRUE, will use bookdown
instead of rmarkdown
for HTML rendering, thus providing section numbering and cross references.embed_fonts
: if TRUE
(default), use local files for fonts used in the template instead of links to Google Web fonts. This leads to bigger files but ensures that the fonts are availablehtml_document
RMarkdown templateExample preamble :
---
title: "My document"
date: "`r Sys.Date()`"
author: John Doe
output:
rmdformats::downcute:
self_contained: true
thumbnails: true
lightbox: true
gallery: false
highlight: tango
---
html_docco
format is heavily inspired from the default one of the docco project.readthedown
is adapted from the corresponding readtheorg
theme of the org-html-themes project, which is itself inspired by the Read the docs Sphinx theme.material
has been taken from the Material design theme for Bootstrap 3 project and its presentation page.robobook
is directly derived from the bookdown project template.downcute
is directly derived from the default theme of the docute project and its adaptation by John Coene for some of its projects documentation.downcute chaos
theme has been created by Zac Garland.rmarkdown
HTML template.html_clean
styling and features are very similar to the ones from the knitrBootstrap package by Jim Hester.Author: juba
Source Code: https://github.com/juba/rmdformats
1666965840
Paginate the HTML Output of R Markdown with CSS for Print. You only need a modern web browser (e.g., Google Chrome or Microsoft Edge) to generate PDF. No need to install LaTeX to get beautiful PDFs.
This R package stands on the shoulders of two giants to support typesetting with CSS for R Markdown documents: Paged.js and ReLaXed (we only borrowed some CSS from the ReLaXed repo and didn't really use the Node package).
You may install this package from Github:
remotes::install_github('rstudio/pagedown')
This package requires a recent version of Pandoc (>= 2.2.3). If you use RStudio, you are recommended to install the latest version (>= 1.2.1335), which has bundled Pandoc 2.x, otherwise you need to install Pandoc separately.
Below are some existing R Markdown output formats and examples.
pagedown::html_paged
)pagedown::thesis_paged
)pagedown::jss_paged
)pagedown::html_resume
)You may want to check out the datadrivencv package, which allows you to build a CV using data from a spreadsheet and pagedown::html_resume
.
pagedown::poster_relaxed
pagedown::poster_jacobs
Want more poster styles? You may take a look at Brent Thorne's posterdown package.
pagedown::business_card
)pagedown::html_letter
)Nick Strayer's CV: https://github.com/nstrayer/cv (also includes instructions on how to build your own CV).
"Template of Exec Summaries with pagedown" by Joshua David Barillas: https://github.com/jdbarillas/executive_summary
Ulrik Lyngs's CVs: https://ulyngs.github.io/pagedown-cv/
Jiena Gu McLellan's CV: https://github.com/jienagu/Jiena_McLellan_CV
Thomas Vroylandt's template for the French Scouts and Guides Association: https://github.com/tvroylandt/sgdf_pagedown
Beatriz Milz's CV: https://beatrizmilz.github.io/resume/resume.html
pagedreport by Thomas Vroylandt and David Keyes which helps using pagedown with some templates proposals: https://github.com/rfortherestofus/pagedreport
Jodavid Ferreira's CV (in Portuguese) : https://jodavid.github.io/cv/ (source: https://github.com/jodavid/cv)
The main authors of this package are Yihui Xie (RStudio) and Romain Lesur. Romain has received a grant from the Shuttleworth Foundation for his work on both Paged.js and pagedown.
You can find the full list of contributors of pagedown here. We always welcome new contributions. In particular, if you are familiar with CSS, we'd love to include your contributions of more creative and beautiful CSS stylesheets in this package. It is also very helpful if you don't know CSS but just tell us the creative and beautiful web pages you have seen, since other CSS experts may be able to port them into pagedown.
Author: rstudio
Source Code: https://github.com/rstudio/pagedownrstudio
License: Unknown, MIT licenses found
1666879469
The rticles package provides a suite of custom R Markdown LaTeX formats and templates for various formats. Most of the templates are provided and maintained by the community, and anyone can contribute a new template. See How to contribute below.
You can install and use rticles from CRAN as follows:
install.packages("rticles")
If you wish to install the development version from GitHub (which often contains new article formats), you can do this:
remotes::install_github("rstudio/rticles")
To use rticles from RStudio, you can access the templates through File -> New File -> R Markdown
. This will open the dialog box where you can select from one of the available templates:
If you are not using RStudio, you’ll also need to install Pandoc following these instructions. Then, use the rmarkdown::draft()
function to create articles:
rmarkdown::draft(
"MyJSSArticle.Rmd", template = "jss", package = "rticles"
)
rmarkdown::draft(
"MyRJournalArticle", template = "rjournal", package = "rticles"
)
This will create a folder containing a Rmd file using the corresponding output format and all the assets required by this format.
Currently included templates and their contributors are the following:
You can also get the list of available journal names with rticles::journals()
.
rticles::journals()
#> [1] "acm" "acs" "aea" "agu"
#> [5] "ajs" "amq" "ams" "arxiv"
#> [9] "asa" "bioinformatics" "biometrics" "copernicus"
#> [13] "ctex" "elsevier" "frontiers" "glossa"
#> [17] "ieee" "ims" "informs" "iop"
#> [21] "isba" "jasa" "jedm" "joss"
#> [25] "jss" "lipics" "lncs" "mdpi"
#> [29] "mnras" "oup_v0" "oup_v1" "peerj"
#> [33] "pihph" "plos" "pnas" "rjournal"
#> [37] "rsos" "rss" "sage" "sim"
#> [41] "springer" "tf" "trb" "wellcomeor"
Those are the values to use within rmarkdown::draft()
.
Under the hood, LaTeX templates are used to ensure that documents conform precisely to submission standards. At the same time, composition and formatting can be done using lightweight markdown syntax, and R code and its output can be seamlessly included using knitr.
There are two main places to get help:
The RStudio community is a friendly place to ask any questions about rticles. Be sure to use the rticles
tag.
Stack Overflow is a great source of answers to common bookdown questions. Use the tags [r][rticles]
if you ask a question.
Please note that the rticles project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.
Most of the templates are contributed directly by the users in the community. If you want rticles to offer a new journal format, you can contribute by the following way.
You may not feel confident enough or may not have time to contribute a new format. By opening a new issue, you can share the idea for this format, and see if someone in the community can help on it.
This is not the best way to quickly get your format included but at least it is a great way to see if others are interested too.
To see the existing suggested formats, just filter issues with the help wanted :heart: label. You can then add a :+1: or help to add the template :wink:.
To contribute a new format, you need to open a new pull request (PR). When opening the PR, you’ll see the PR template explaining how to proceed and what is important to check. Please follow it.
Even if you are just starting or you are not finished, you share your work by creating a draft PR. It is a great way to let us know that you are still working on it (like these opened ones), and it is also a great way to ask for help from the community.
When you are ready, you can submit the PR for review, and we will iterate until it is merged.
The best way to get started is to look at the previous examples of submitted PR. You’ll find links to them in the table above.
All the rticles
format are build similarly by providing a new pandoc tex template to replace the default one. You’ll learn more about pandoc templates in these places:
You can study existing formats to see how all this works.
Author: rstudio
Source Code: https://github.com/rstudio/rticles
1666862520
The goal of the blogdown package is to provide a powerful and customizable website output format for R Markdown. Use dynamic R Markdown documents to build webpages featuring:
R code (or other programming languages that knitr supports),
automatically rendered output such as graphics, tables, analysis results, and HTML widgets, and
technical writing elements such as citations, footnotes, and LaTeX math, enabled by the bookdown package.
By default, blogdown uses Hugo, a popular open-source static website generator, which provides a fast and flexible way to build your site content to be shared online. Other website generators like Jekyll and Hexo are also supported.
A useful feature of blogdown sites, compared to other R Markdown-based websites, is that you may organize your website content (including R Markdown files) within subdirectories. This makes blogdown a good solution not just for blogging or sites about R — it can also be used to create general-purpose websites to communicate about data science, statistics, data visualization, programming, or education.
You can install the package via CRAN as follows:
install.packages('blogdown')
If you want to use the development version of the blogdown package, you can install the package from GitHub via the remotes package:
remotes::install_github('rstudio/blogdown')
You may create a new site via the function blogdown::new_site()
under an empty directory. It will create a skeleton site, download a Hugo theme from Github, add some sample content, launch a web browser and you will see the new site. The sample blog post hello-world.Rmd
should be opened automatically, and you can edit it. The website will be automatically rebuilt and the page will be refreshed after you save the file.
If you use RStudio, you can create a new RStudio project for your website from the menu File -> New Project -> New Directory -> Website using blogdown
.
The function blogdown::serve_site()
may be the most frequently used function in this package. It builds the website, loads it into your web browser, and automatically refreshes the browser when you update the Markdown or R Markdown files. Do not use the command line hugo server
to build or serve the site. It only understands plain Markdown files, and cannot build R Markdown.
You may not be satisfied with the default site created from new_site()
. There are two things you may want to do after your first successful experiment with blogdown:
theme
argument of new_site()
.There are two main places to get help:
The RStudio community is a friendly place to ask any questions about blogdown. Be sure to use the blogdown
tag.
Stack Overflow is a great source of answers to common blogdown questions. Use the tags [r][blogdown]
if you ask a question.
Please note that the blogdown project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.
Author: rstudio
Source Code: https://github.com/rstudio/blogdown
1665474900
Yet another second editor in RStudio.
The Monaco editor is the code editor which powers 'VS Code'. It is particularly well developed for JavaScript. In addition to the built-in features of the Monaco editor, the widget allows to prettify multiple languages, to view the HTML rendering of Markdown code, and to view and resize SVG images.
With the help of htmltools::browsable
, one can open two Monaco editors in the RStudio viewer pane:
The Monaco editor has many options. If you would like some of them to be available in the monaco
package, please fill an issue.
As any HTML widget, the Monaco editor widget can be used in Shiny apps:
This app uses the sass
package to compile some SCSS code to CSS code. It is one of the examples provided in the monaco
package.
monaco
widget but using the Shiny app locks RStudio.Author: stla
Source Code: https://github.com/stla/monaco
License: View license
1665471060
A second editor in RStudio!
This package makes available the Ace editor as a HTML widget.
It also makes available the Ace diff editor, which highlights the differences between two files:
Related project: monaco, the Monaco editor as a HTML widget. The Monaco editor has more features for JavaScript, CSS, and related languages (JSX, SCSS, TypeScript). The Ace editor has support for more languages.
Author: stla
Source Code: https://github.com/stla/aceEditor
License: View license
1661581500
Database Connection Pooling in R
The goal of the pool
package is to abstract away the logic of connection management and the performance cost of fetching a new connection from a remote database. These concerns are especially prominent in interactive contexts, like Shiny apps (which connect to a remote database) or even at the R console. So, while this package is of most practical value to Shiny developers, there is no harm if it is used in other contexts. Since pool
integrates with both DBI
and dplyr
, there are very few things that will be new to you, if you're already using either of those packages. Essentially, you shouldn't feel the difference, with the exception of creating and closing a Pool object (as opposed to connecting and disconnecting a DBIConnection object).
Here’s a simple example of using a pool within a Shiny app (feel free to try it yourself):
library(shiny)
library(dplyr)
library(pool)
pool <- dbPool(
drv = RMySQL::MySQL(),
dbname = "shinydemo",
host = "shiny-demo.csa7qlmguqrf.us-east-1.rds.amazonaws.com",
username = "guest",
password = "guest"
)
onStop(function() {
poolClose(pool)
})
ui <- fluidPage(
textInput("ID", "Enter your ID:", "5"),
tableOutput("tbl"),
numericInput("nrows", "How many cities to show?", 10),
plotOutput("popPlot")
)
server <- function(input, output, session) {
output$tbl <- renderTable({
pool %>% tbl("City") %>% filter(ID == !!input$ID) %>% collect()
})
output$popPlot <- renderPlot({
df <- pool %>% tbl("City") %>% head(input$nrows) %>% collect()
pop <- df$Population
names(pop) <- df$Name
barplot(pop)
})
}
shinyApp(ui, server)
The pool
package adds a new level of abstraction when connecting to a database: instead of directly fetching a connection from the database, you will create an object (called a pool) with a reference to that database. The pool holds a number of connections to the database. Some of these may be currently in-use and some of these may be idle, waiting for a query to request them. Each time you make a query, you are querying the pool, rather than the database. Under the hood, the pool will either give you an idle connection that it previously fetched from the database or, if it has no free connections, fetch one and give it to you. You never have to create or close connections directly: the pool knows when it should grow, shrink or keep steady. You only need to close the pool when you’re done.
When you’re connecting to a database, it is important to manage your connections: when to open them (taking into account that this is a potentially long process for remote databases), how to keep track of them, and when to close them. This is always true, but it becomes especially relevant for Shiny apps, where not following best practices can lead to many slowdowns (from inadvertently opening too many connections) and/or many leaked connections (i.e. forgetting to close connections once you no longer need them). Over time, leaked connections could accumulate and substantially slow down your app, as well as overwhelming the database itself.
Oversimplifying a bit, we can think of connection management in Shiny as a spectrum from the extreme of just having one connection per app (potentially serving several sessions of the app) to the extreme of opening (and closing) one connection for each query you make. Neither of these approaches is great. You can expand either of the arrows below to see the source code for each extreme, but that is not essential to understanding the problems described below.
oneConnectionPerApp.R
library(shiny)
library(dplyr)
library(DBI)
conn <- dbConnect(
drv = RMySQL::MySQL(),
dbname = "shinydemo",
host = "shiny-demo.csa7qlmguqrf.us-east-1.rds.amazonaws.com",
username = "guest",
password = "guest"
)
onStop(function() {
dbDisconnect(conn)
})
ui <- fluidPage(
textInput("ID", "Enter your ID:", "5"),
tableOutput("tbl"),
numericInput("nrows", "How many cities to show?", 10),
plotOutput("popPlot")
)
server <- function(input, output, session) {
output$tbl <- renderTable({
conn %>% tbl("City") %>% filter(ID == !!input$ID) %>% collect()
})
output$popPlot <- renderPlot({
df <- conn %>% tbl("City") %>% head(input$nrows) %>% collect()
pop <- df$Population
names(pop) <- df$Name
barplot(pop)
})
}
shinyApp(ui, server)
oneConnectionPerQuery.R
library(shiny)
library(dplyr)
library(DBI)
args <- list(
drv = RMySQL::MySQL(),
dbname = "shinydemo",
host = "shiny-demo.csa7qlmguqrf.us-east-1.rds.amazonaws.com",
username = "guest",
password = "guest"
)
ui <- fluidPage(
textInput("ID", "Enter your ID:", "5"),
tableOutput("tbl"),
numericInput("nrows", "How many cities to show?", 10),
plotOutput("popPlot")
)
server <- function(input, output, session) {
output$tbl <- renderTable({
conn <- do.call(dbConnect, args)
on.exit(dbDisconnect(conn))
conn %>% tbl("City") %>% filter(ID == !!input$ID) %>% collect()
})
output$popPlot <- renderPlot({
conn <- do.call(dbConnect, args)
on.exit(dbDisconnect(conn))
df <- conn %>% tbl("City") %>% head(input$nrows) %>% collect()
pop <- df$Population
names(pop) <- df$Name
barplot(pop)
})
}
shinyApp(ui, server)
Opening only one connection per app makes it fast (because, in the whole app, you only fetch one connection) and your code is kept as simple as possible. However:
While the other extreme of opening (and closing) one connection for each query you make resolves all of these points, it is terribly slow (each time we need to access the database, we first have to fetch a connection), and you need a lot more (boilerplate) code to connect and disconnect the connection within each reactive/function.
The pool
package was created so you don't have to worry about this at all. Since pool
abstracts away the logic of connection management, for the vast majority of cases, you never have to deal with connections directly. Since the pool “knows” when it should have more connections and how to manage them, you have all the advantages of the second approach (one connection per query), without the disadvantages. You are still using one connection per query, but that connection is always fetched and returned to the pool, rather than getting it from the database directly. This is a whole lot faster and more efficient. Finally, the code is kept just as simple as the code in the first approach (only one connection for the entire app). In fact, if you look back at the pool
Shiny app example above, you will notice that the code structure is essentially the same that you'd use to open a connection at the start of an app and close it at the end.
Author: rstudio
Source Code: https://github.com/rstudio/pool
1661514327
This package provides a function datatable()
to display R data via the DataTables library (N.B. not to be confused with the data.table package).
You may install the stable version from CRAN, or the development version using remotes:
# install from CRAN
install.packages('DT')
# or the development version if necessary
remotes::install_github('rstudio/DT')
# then try DT::datatable(iris) as a hello world example
See the full documentation at https://rstudio.github.io/DT/. Please use Github issues only if you want to file bug reports or feature requests, and you are expected to ask questions on StackOverflow with at least the tags r
and dt
.
Author: rstudio
Source Code: https://github.com/rstudio/DT
License: View license
1661362740
The goal of shinysnippets is to save development time while taking advantage of Rstudio snippets for Shiny applications.
You can install the dev of {shinysnippets} from GitHub:
remotes::install_github("Thinkr-open/shinysnippets")
Then run:
shinysnippets::add_snippets()
You’ll be asked to validate the writing of the snippets in ~/.R/snippets/r.snippets
.
Restart RStudio to make these snippets effective.
Copy and paste these snippets to Tools > Global Options > Code > Editing > Edit Snippets.
snippet module
${1:name}ui <- function(id){
ns <- NS(id)
tagList(
)
}
${1:name} <- function(input, output, session){
ns <- session\$ns
}
# Copy in UI
${1:name}ui("${1:name}ui")
# Copy in server
callModule(${1:name}, "${1:name}ui")
snippet observe_event
observeEvent( ${1:event} , {
})
snippet sidebar_page
library(shiny)
ui <- fluidPage(
titlePanel( "${1:title}" ),
sidebarLayout(
sidebarPanel(
),
mainPanel(
)
)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
snippet with_progress
withProgress( message = "${1:message}" , {
})
Please note that the ‘shinysnippets’ project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.
Author: ThinkR-open
Source Code: https://github.com/ThinkR-open/shinysnippets
License: Unknown, MIT licenses found
1661294880
shinytest provides a simulation of a Shiny app that you can control in order to automate testing. shinytest uses a snapshot-based testing strategy: the first time it runs a set of tests for an application, it performs some scripted interactions with the app and takes one or more snapshots of the application’s state. Subsequent runs perform the same scripted interactions then compare the results; you'll get an error if they're different.
To install the current release version:
install.packages("shinytest")
See the getting started guide to learn how to use shinytest.
Author: rstudio
Source Code: https://github.com/rstudio/shinytest
License: View license
1661232003
The fontawesome R package makes it very easy to insert Font Awesome icons into R Markdown documents and Shiny apps (or, anywhere else you need to put them).
The fa()
function can be used to insert an FA icon. For example, we can get the r-project icon in steelblue
:
fa(name = "r-project", fill = "steelblue")
#> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 581 512" class="rfa" style="height:0.75em;fill:steelblue;position:relative;"><path d="M581 226.6C581 119.1 450.9 32 290.5 32S0 119.1 0 226.6C0 322.4 103.3 402 239.4 418.1V480h99.1v-61.5c24.3-2.7 47.6-7.4 69.4-13.9L448 480h112l-67.4-113.7c54.5-35.4 88.4-84.9 88.4-139.7zm-466.8 14.5c0-73.5 98.9-133 220.8-133s211.9 40.7 211.9 133c0 50.1-26.5 85-70.3 106.4-2.4-1.6-4.7-2.9-6.4-3.7-10.2-5.2-27.8-10.5-27.8-10.5s86.6-6.4 86.6-92.7-90.6-87.9-90.6-87.9h-199V361c-74.1-21.5-125.2-67.1-125.2-119.9zm225.1 38.3v-55.6c57.8 0 87.8-6.8 87.8 27.3 0 36.5-38.2 28.3-87.8 28.3zm-.9 72.5H365c10.8 0 18.9 11.7 24 19.2-16.1 1.9-33 2.8-50.6 2.9v-22.1z"/></svg>
As can be seen, what we really get from the function is an SVG object that represents the icon. This can be directly used within R Markdown with:
{text} `r fa(...)` {text}
Font Awesome SVG icons are great to use instead of <i>
tags + font files for a few reasons:
<i>
tag requires computation to obtain the icon (<svg>
tags represent the actual icon)<i>
tags has a 'being online' requirement since network activity is necessary for resolving these tags (SVGs in fontawesome are stored in the package, so, no Internet connectivity is necessary for that)Here is an example R Markdown document that includes Font Awesome icons:
---
title: "Font Awesome in R Markdown"
output: html_document
---
```{r load_packages, message=FALSE, warning=FALSE, include=FALSE}
library(fontawesome)
```
# Just a few tests with `r fa("font-awesome-logo-full", fill = "forestgreen")`
It works well in headings...
# `r fa("r-project", fill = "steelblue")` H1 Heading
## `r fa("r-project", fill = "steelblue")` H2 Heading
### `r fa("r-project", fill = "steelblue")` H3 Heading
#### `r fa("r-project", fill = "steelblue")` H4 Heading
##### `r fa("r-project", fill = "steelblue")` H5 Heading
...and works equally well within inline text: `r fa("r-project", fill = "steelblue")`.
This will appear, when knit, as:
Here’s a Shiny app (from the Shiny Gallery) that’s been slightly modified to incorporate Font Awesome icons in the text above the three search fields:
library(shiny)
library(DT)
library(ggplot2)
library(fontawesome)
ui <- fluidPage(
titlePanel("Basic DataTable"),
# Create a new Row in the UI for selectInputs
fluidRow(
column(
width = 4,
selectInput(
inputId = "man",
label = tags$p(fa("car", fill = "purple"), "Manufacturer:"),
choices = c(
"All",
unique(as.character(mpg$manufacturer))))
),
column(
width = 4,
selectInput(
inputId = "trans",
label = tags$p(fa("car", fill = "forestgreen"), "Transmission:"),
choices = c(
"All",
unique(as.character(mpg$trans))))
),
column(
width = 4,
selectInput(
inputId = "cyl",
label = tags$p(fa("car", fill = "steelblue"), "Cylinders:"),
choices = c(
"All",
unique(as.character(mpg$cyl))))
)
),
# Create a new row for the table.
fluidRow(
dataTableOutput("table")
)
)
server <- function(input, output) {
# Filter data based on selections
output$table <- renderDataTable({
data <- mpg
if (input$man != "All") {
data <- data[data$manufacturer == input$man,]
}
if (input$cyl != "All") {
data <- data[data$cyl == input$cyl,]
}
if (input$trans != "All") {
data <- data[data$trans == input$trans,]
}
data
})
}
shinyApp(ui = ui, server = server)
The Shiny app will look something like this:
Please note that using shiny::icon()
in place of fontawesome::fa()
will still work. Internally, the icon()
function will call fontawesome
's fa_i()
function, which generates an old-school <i>
tag for the icon.
Want to try this out? The fontawesome package can be installed from CRAN:
install.packages("fontawesome")
Also, you can install the development version of fontawesome from GitHub:
devtools::install_github("rstudio/fontawesome")
If you encounter a bug, have usage questions, or want to share ideas to make this package better, feel free to file an issue.
Code of Conduct
Please note that the rstudio/fontawesome
project is released with a contributor code of conduct.
By participating in this project you agree to abide by its terms.
🏛️ Governance
This project is primarily maintained by Rich Iannone. Other authors may occasionally assist with some of these duties.
Author: rstudio
Source Code: https://github.com/rstudio/fontawesome
License: Unknown, Unknown licenses found