Shiny 0.10 is now available on CRAN.

Interactive documents

In this release, the biggest changes were under the hood to support the creation of interactive documents. If you haven’t had a chance to check out interactive documents, we really encourage you to do so—it may be the easiest way to learn Shiny.

New layout functions

Three new functions—flowLayout(), splitLayout(), and inputPanel()—were added for putting UI elements side by side.

  • flowPanel() lays out its children in a left-to-right, top-to-bottom arrangement.
  • splitLayout() evenly divides its horizontal space among its children (or unevenly divides if cellWidths argument is provided).
  • inputPanel() is like flowPanel(), but with a light grey background, and is intended for encapsulating small input controls wherever vertical space is at a premium.

A new logical argument inline was also added to checkboxGroupInput() and radioButtons() to arrange check boxes and radio buttons horizontally.

Custom validation error messages

Sometimes you don’t want your reactive expressions or output renderers in server.R to proceed unless certain input conditions are satisfied, e.g. a select input value has been chosen, or a sensible combination of inputs has been provided. In these cases, you might want to stop the render function quietly, or you might want to give the user a custom message. In shiny 0.10.0, we introduced the functions validate() and need() which you can use to enforce validation conditions. This won’t be the last word on input validation in Shiny, but it should be a lot safer and more convenient than how most of us have been doing it.

See the article Write error messages for your UI with validate for details and examples.

Sever-side processing for Selectize input

In the previous release of Shiny, we added support for Selectize, a powerful select box widget. At that time, our implementation passed all of the data to the web page and used JavaScript to do any paging, filtering, and sorting. It worked great for small numbers of items but didn’t scale well beyond a few thousand items.

For Shiny 0.10, we greatly improved the performance of our existing client-side Selectize binding, but also added a new mode that allows the paging, filtering, and sorting to all happen on the server. Only the results that are actually displayed are downloaded to the client. This approach works well for hundreds of thousands or millions of rows.

For more details and examples, see the article Using selectize input on shiny.rstudio.com.

htmltools

We also split off Shiny’s HTML generating library (tags and friends) into a separate htmltools package. If you’re writing a package that needs to generate HTML programmatically, it’s far easier and safer to use htmltools than to paste HTML strings together yourself. We’ll have more to share about htmltools in the months to come.

Other changes

  • New actionLink() input control: behaves like actionButton() but looks like a link
  • renderPlot() now calls print() on its result if it’s visible–no more explicit print() required for ggplot2
  • Sliders and select boxes now use a fixed horizontal size instead of filling up all available horizontal space; pass width="100%" if you need the old behavior
  • The session object that can be passed into a server function is now documented: see ?session
  • New reactive domains feature makes it easy to get callbacks when the current session ends, without having to pass session everywhere
  • Thanks to reactive domains, by default, observers now automatically stop executing when the Shiny session that created them ends
  • shinyUI and shinyServer

For the full list, you can take a look at the NEWS file. Please let us know if you have any comments or questions.

R Markdown’s new interactive documents provide a quick, light-weight way to use Shiny. An interactive document embeds Shiny elements in an R Markdown report. The report becomes “live”, a choose your own adventure that readers can control and explore. Interactive documents are easy to create and easy to share.

Create an interactive document

To create an interactive document use RStudio to create a new R Markdown file, choose the Shiny document template, then click “Run Document” to show a preview:


storms.002

Embed R code chunks in your report where you like. Interactive documents use the same syntax as R Markdown and knitr. Set echo = FALSE. Your reader won’t see the code, just its results.

 

  storms2.001

Include Shiny widgets and outputs in your code chunks. R Markdown will insert the widgets directly into your final document. When a reader toggles a widget, the parts of the document that depend on it will update instantly.

 storms.003

That’s it! No extra files are needed.

Note that in order to use interactive documents you should be running the latest version of RStudio (v0.98.932 or higher). Alternatively if you are not using RStudio be sure to follow the directions here to install all of the required components.

Share your document

Interactive documents can be run locally on the desktop or be deployed Shiny Server v1.2 or ShinyApps just like any other Shiny application. See the RMarkdown v2 website for more details on deploying interactive documents.

Use pre-packaged tools

Interactive documents make it easy to insert powerful tools into a report. For example, you can insert a kmeans clustering tool into your document with one line of code, as below. kmeans_cluster is a widget built from a Shiny app and intended for use in interactive documents.

storms.004

You can build your own widgets with shinyApp, a new function that repackages Shiny apps as functions. shinyApp is easy to use. Its first argument takes the code that appears in an app’s ui.R file. The second argument takes the code that appears in the app’s server.R file. The source of kmeans_cluster reveals how simple this is.

Be a hero

Ready to be a hero? You can use the `shinyApp` function to make out of the box widgets that students, teachers, and data scientists will use everyday. Widgets can

  • fit models
  • compare distributions
  • visualize data
  • demonstrate teaching examples
  • act as quizzes or multiple choice questions
  • and more

These widgets are not made yet, they are low hanging fruit for any Shiny developer. If you know how to program with Shiny (or want to learn), and would like to make your mark on R, consider authoring a package that makes widgets available for interactive documents.

Get started!

To learn more about interactive documents visit http://rmarkdown.rstudio.com/authoring_shiny.html.

 

People rarely agree on a best authoring tool or language. Some people cannot live without \LaTeX{} because of the beauty and quality of its PDF output. Some \feel{} \uncomfortable{} \with{} \backslashes{}, and would rather live in another World Word. We have also witnessed the popularity of Markdown, an incredibly simple language (seriously? a LANGUAGE?) that has made reproducible research much easier.

Thinking of all these tools and languages, every developer will dream about “One ring to rule them all“. \section{}, <h1></h1>, ===, #, … Why cannot we write the first-level section header in a single way? Yes, we are aware of the danger of “adding yet another so-called universal standard that covers all the previous standards”. However, we believe Pandoc has done a fairly good job in terms of “yet another Markdown standard”. Standing on the shoulders of Pandoc, today we are excited to announce the second episode of our journey into the development of the tools for authoring dynamic documents:

The Return of R Markdown!

The R package markdown (plus knitr) was our first version of R Markdown. The primary output format was HTML, which certainly could not satisfy all users in the World Word. It did not have features like citations, footnotes, or metadata (title, author, and date, etc), either. When we were asked how one could convert Markdown to PDF/Word, we used to tell users to try Pandoc. The problem is that Pandoc’s great power comes with a lot of command line options (more than 70), and knitr has the same problem of too many options. That is why we created the second generation of R Markdown, represented by the rmarkdown package, to provide reasonably good defaults and an R-friendly interface to customize Pandoc options.

The new version of RStudio (v0.98.932) includes everything you need to use R Markdown v2 (including pandoc and the rmarkdown package). If you are not using RStudio you can install rmarkdown and pandoc separately as described here. To get started with a “Hello Word” example, simply click the menu File -> New File -> R Markdown in RStudio IDE. You can choose the output format from the drop-down menu on the toolbar.

R Markdown Formats

The built-in output formats include HTML, LaTeX/PDF, Word, Beamer slides, HTML5 presentations, and so on. Pandoc’s Markdown allows us to write richer content such as tables, citations, and footnotes. For power users who understand LaTeX/HTML, you can even embed raw LaTeX/HTML code in Markdown, and Pandoc is smart enough to process these raw fragments. If you cannot remember the possible options for a certain output format in the YAML metadata (data between --- and --- in the beginning of a document), you can use the Settings button on the toolbar.

Extensive documentation for R Markdown v2 and all of it’s supported output formats are available on the new R Markdown website at http://rmarkdown.rstudio.com.

We understand users will never be satisfied by our default templates, regardless of how hard we try to make them appealing. The rmarkdown package is fully customizable and extensible in the sense that you can define your custom templates and output formats. You want to contribute an article to The R Journal, or JSS (Journal of Statistical Software), but prefer writing in Markdown instead of LaTeX? No problem! Pandoc also supports many other output formats, and you want EPUB books, or a different type of HTML5 slides? No problem! Not satisfied with one single static output document? You can embed interactive widgets into R Markdown documents as well! Let there be Shiny! The more you learn about rmarkdown and Pandoc, the more freedom you will get.

For a brief video introduction, you may watch the talk below (jump to 18:30 if you only want to see the demos):

The rmarkdown package is open-source (GPL-3) and is both included in the RStudio IDE and available on GitHub. The package is not on CRAN yet, but will be there as soon as we make all the improvements requested by early users.

To clarify the relationship between rmarkdown and RStudio IDE, our IDE is absolutely not the only way to compile R Markdown documents. You are free to call functions in rmarkdown in any environment. Please check out the R package documentation, in particular, the render() function in rmarkdown.

Please let us know if you have any questions or comments, and your feedback is greatly appreciated. We hope you will enjoy R Markdown v2.

Keep Calm and Markdown

Today we’re very pleased to announce a new version of RStudio (v0.98.932) which is available for download now. New features in this release include:

  • A next generation implementation of R Markdown with a raft of new features including support for HTML, PDF, and Word output, many new options for customizing document appearance, and the ability to create presentations (Beamer or HTML5).
  • Interactive Documents (Shiny meets R Markdown). Readers can now change the parameters underlying your analysis and see the results immediately. Interactive Documents make it easier than ever to use Shiny!
  • Shareable notebooks from R scripts. Notebooks include all R code and generated output, and can be rendered in HTML, PDF, and Word formats.
  • Enhanced debugging including support for the new R 3.1 debugging commands to step into function calls and finish the current loop or function.
  • Various source editor enhancements including new syntax highlighting modes for XML, YAML, SQL, Python, and shell scripts. You can also execute Python and shell scripts directly from the editor using Ctrl+Shift+Enter.
  • Integrated tools for Shiny development including the ability to run applications within an IDE pane as well as Run/Reload applications with a keyboard shortcut (Ctrl+Shift+Enter).
  • A new devtools mode for package development (uses devtools for check, document, test, build, etc.)
  • Contextual Git/SVN menu that enables quick access to per-file revision history and selection-aware View/Blame for projects hosted on GitHub.
  • Fast lookup of shortcuts using the new keyboard shortcut quick-reference card (Alt+Shift+K)

See the release notes for a full list of what’s changed and see Yihui Xie’s post on R Markdown v2 for more on what’s new there.

We’ll be posting additional articles over the next few days that describe the new features in more depth. In the meantime we hope you download the new version and as always let us know how it’s working and what else you’d like to see.

We’ve added two new features that make it easier to learn Shiny with the Shiny Dev Center.

  1. Disqus comments – Each lesson and article on the Dev Center now has its own comments section. Use the comments section to start a discussion or to leave feedback about the articles.

  2. How to get help with Shiny – We’ve added a new article, How to get help with Shiny, which explains the best ways to get help with Shiny and R. As an open source language, R doesn’t have a paid support team, which makes getting help with R (and Shiny) a little different than for paid software.

Are you curious about the Shiny Dev Center? The Dev Center is located at shiny.rstudio.com, a central repository of information on Shiny. At the Dev Center, you will find a tutorial, documentation, articles on Shiny, and example Shiny apps.

I’m very excited to announce dplyr 0.2. It has three big features:

  • improved piping courtesy of the magrittr package

  • a vastly more useful implementation of do()

  • five new verbs: sample_n(), sample_frac(), summarise_each(), mutate_each and glimpse().

These features are described in more detail below. To learn more about the 35 new minor improvements and bug fixes, please read the full release notes.

Improved piping

dplyr now imports %>% from the magrittr package by Stefan Milton Bache. I recommend that you use this instead of %.% because it is easier to type (since you can hold down the shift key) and is more flexible. With you %>%, you can control which argument on the RHS receives the LHS with the pronoun .. This makes %>% more useful with base R functions because they don’t always take the data frame as the first argument. For example you could pipe mtcars to xtabs() with:

mtcars %>% xtabs( ~ cyl + vs, data = .)

dplyr only exports %>% from magrittr, but magrittr contains many other useful functions. To use them, load magrittr explicitly with library(magrittr). For more details, see vignette("magrittr").
%.% will be deprecated in a future version of dplyr, but it won’t happen for a while. I’ve deprecated chain() to encourage a single style of dplyr usage: please use %>% instead.

Do

do() has been completely overhauled, and group_by() + do() is now equivalent in power to plyr::dlply(). There are two ways to use do(), either with multiple named arguments or a single unnamed arguments. If you use named arguments, each argument becomes a list-variable in the output. A list-variable can contain any arbitrary R object which makes this form of do() useful for storing models:

library(dplyr)
models %>% group_by(cyl) %>% do(model = lm(mpg ~ wt, data = .))
models %>% summarise(rsq = summary(model)$r.squared)

If you use an unnamed argument, the result should be a data frame. This allows you to apply arbitrary functions to each group.

mtcars %>% group_by(cyl) %>% do(head(., 1))

Note the use of the pronoun . to refer to the data in the current group.
do() also has an automatic progress bar. It appears if the computation takes longer than 2 seconds and estimates how long the job will take to complete.

New verbs

sample_n() randomly samples a fixed number of rows from a tbl; sample_frac() randomly samples a fixed fraction of rows. They currently only work for local data frames and data tables.
summarise_each() and mutate_each() make it easy to apply one or more functions to multiple columns in a tbl. These works for all srcs that summarise() and mutate() work for.
glimpse() makes it possible to see all the columns in a tbl, displaying as much data for each variable as can be fit on a single line.

We’re pleased to announce a new version of roxygen2. Roxygen2 allows you to write documentation comments that are automatically converted to R’s standard Rd format, saving you time and reducing duplication. This release is a major update that provides enhanced error handling and considerably safer default behaviour. Roxygen2 now adds a comment to all generated files so that you know they shouldn’t be edited by hand. This also ensures that roxygen2 will never overwrite a file that it did not create, and can automatically remove files that are no longer needed.

I’ve also written some vignettes to help you understand how to use roxygen2. Six new vignettes provide a comprehensive overview of using roxygen2 in practice. Run browseVignettes("roxygen2") to read them. In an effort to make roxygen2 easier to use and more consistent between package authors, I’ve made parsing considerably stricter, and made sure that all errors give you the line number of the associated roxygen block. Every input is now checked to make sure that it has (e.g. every { has a matching }). This should prevent frustrating errors that require careful reading of .Rd files. Similarly, @section titles and @export tags can now only span a single line as this prevents a number of common bugs.

Other features include two new tags @describeIn and @field, and you can document objects (like datasets) by documenting their name as a string. For example, to document a dataset called mydata, you can do:

#' Mydata set
#'
#' Some data I collected about myself
"mydata"

To see a complete list of all bug fixes and improvements, please see the release notes for roxygen2 4.0.0 for details. Roxygen2 4.0.1 fixed a couple of minor bugs and majorly improved the upgrade process.

reshape2 1.4 is now available on CRAN. This version adds a number of useful arguments and messages, but mostly importantly it gains a C++ implementation of melt.data.frame(). This new method should be much much faster (>10x) and does a better job of preserving existing attributes. For full details, see the release notes on github.

The C++ implementation of melt was contributed by Kevin Ushey, who we’re very pleased to announce has joined RStudio. You may be familiar with Kevin from his contributions to Rcpp, or his CRAN packages Kmisc and timeit.

Shiny apps use an HTML interface, which means that you can change the visual appearance of your apps quickly and simply with CSS files. Would you like to know how? I posted a new article that will step you through the options at the Shiny Dev Center. Check it out here.

Image

We are happy to announce the availability of v1.1 of RStudio Shiny Server Pro, our commercial server for deploying Shiny applications.  In this release we took your feedback and made it easier for you to integrate Shiny Server Pro into your production environments.  With Shiny Server Pro v1.1 you now can:

  • Control access to your applications with Google Authentication (OAuth2).
  • Create sessions and authenticate with PAM (auth_pam and pam_sessions_profile).
  • Set the version of R that is used per application and/or per user
  • Customize page templates for directory listings and error pages.
  • Monitor service health and get additional metrics with a new health check endpoint.
  • Provide custom environment variables to a Shiny process using Bash profiles
  • Configure apps to run using the authenticated user’s account with custom environment variables from Bash or PAM
  • Launch Shiny apps with a prefix command such as ‘nice’ allowing you to prioritize compute resources per application or  per user

If you haven’t tried Shiny Server Pro yet, download a copy here.

 

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 607 other followers

RStudio is an affiliated project of the Foundation for Open Access Statistics

Follow

Get every new post delivered to your Inbox.

Join 607 other followers