You are currently browsing the category archive for the ‘Shiny’ category.

Today we’re excited to announce htmlwidgets, a new framework that brings the best of JavaScript data visualization libraries to R. There are already several packages that take advantage of the framework (leaflet, dygraphs, networkD3, DataTables, and rthreejs) with hopefully many more to come.

An htmlwidget works just like an R plot except it produces an interactive web visualization. A line or two of R code is all it takes to produce a D3 graphic or Leaflet map. Widgets can be used at the R console as well as embedded in R Markdown reports and Shiny web applications. Here’s an example of using leaflet directly from the R console:

rconsole.2x

When printed at the console the leaflet widget displays in the RStudio Viewer pane. All of the tools typically available for plots are also available for widgets, including history, zooming, and export to file/clipboard (note that when not running within RStudio widgets will display in an external web browser).

Here’s the same widget in an R Markdown report. Widgets automatically print as HTML within R Markdown documents and even respect the default knitr figure width and height.

rmarkdown.2x

Widgets also provide Shiny output bindings so can be easily used within web applications. Here’s the same widget in a Shiny application:

shiny.2x

Bringing JavaScript to R

The htmlwidgets framework is a collaboration between Ramnath Vaidyanathan (rCharts), Kenton Russell (Timely Portfolio), and RStudio. We’ve all spent countless hours creating bindings between R and the web and were motivated to create a framework that made this as easy as possible for all R developers.

There are a plethora of libraries available that create attractive and fully interactive data visualizations for the web. However, the programming interface to these libraries is JavaScript, which places them outside the reach of nearly all statisticians and analysts. htmlwidgets makes it extremely straightforward to create an R interface for any JavaScript library.

Here are a few widget libraries that have been built so far:

  • leaflet, a library for creating dynamic maps that support panning and zooming, with various annotations like markers, polygons, and popups.
  • dygraphs, which provides rich facilities for charting time-series data and includes support for many interactive features including series/point highlighting, zooming, and panning.
  • networkD3, a library for creating D3 network graphs including force directed networks, Sankey diagrams, and Reingold-Tilford tree networks.
  • DataTables, which displays R matrices or data frames as interactive HTML tables that support filtering, pagination, and sorting.
  • rthreejs, which features 3D scatterplots and globes based on WebGL.

All of these libraries combine visualization with direct interactivity, enabling users to explore data dynamically. For example, time-series visualizations created with dygraphs allow dynamic panning and zooming:

NewHavenTemps

Learning More

To learn more about the framework and see a showcase of the available widgets in action check out the htmlwidgets web site. To learn more about building your own widgets, install the htmlwidgets package from CRAN and check out the developer documentation.

 

Shiny v0.10.2 has been released to CRAN. To install it:

install.packages('shiny')

This version of Shiny requires R 3.0.0 or higher (note the current version of R is 3.1.1). R 2.15.x is no longer supported.

Here are the most prominent changes:

  • File uploading via fileInput() now works for Internet Explorer 8 and 9. Note, however, that IE 8/9 do not support multiple files from a single file input. If you need to upload multiple files, you must use one file input for each file. Unlike in modern web browsers, no progress bar will display when uploading files in IE 8/9.
  • Shiny now supports single-file applications: instead of needing two separate files, server.R and ui.R, you can now create an application with single file named app.R. This also makes it easier to distribute example Shiny code, because you can run an entire app by simply copying and pasting the code for a single-file app into the R console. Here’s a simple example of a single-file app:
    ## app.R
    server <- function(input, output) {
      output$distPlot <- renderPlot({
        hist(rnorm(input$obs), col = 'darkgray', border = 'white')
      })
    }
    
    ui <- shinyUI(fluidPage(
      sidebarLayout(
        sidebarPanel(
          sliderInput("obs", "Number of observations:",
                      min = 10, max = 500, value = 100)
        ),
        mainPanel(plotOutput("distPlot"))
      )
    ))
    
    shinyApp(ui = ui, server = server)
    

    See the single-file app article for more.

  • We’ve added progress bars, which allow you to indicate to users that something is happening when there’s a long-running computation. The progress bar will show at the top of the browser window, as shown here:progress
    Read the progress bar article for more.
  • We’ve upgraded the DataTables Javascript library from 1.9.4 to 1.10.2. We’ve tried to support backward compatibility as much as possible, but this might be a breaking change if you’ve customized the DataTables options in your apps. This is because some option names have changed; for example, aLengthMenu has been renamed to lengthMenu. Please read the article on DataTables on the Shiny website for more information about updating Shiny apps that use DataTables 1.9.4.

In addition to the changes listed above, there are some smaller updates:

  • Searching in DataTables is case-insensitive and the search strings are not treated as regular expressions by default now. If you want case-sensitive searching or regular expressions, you can use the configuration options search$caseInsensitive and search$regex, e.g. renderDataTable(..., options = list(search = list(caseInsensitve = FALSE, regex = TRUE))).
  • Shiny has switched from reference classes to R6.
  • Reactive log performance has been greatly improved.
  • Exported createWebDependency. It takes an htmltools::htmlDependency object and makes it available over Shiny’s built-in web server.
  • Custom output bindings can now render htmltools::htmlDependency objects at runtime using Shiny.renderDependencies().

Please read the NEWS file for a complete list of changes, and let us know if you have any comments or questions.

ShinyApps.io dashboard

Some of the most innovative Shiny apps share data across user sessions. Some apps share the results of one session to use in future sessions, others track user characteristics over time and make them available as part of the app.

This level of sophistication creates tricky design choices when you host your app on a server. A nimble server will open new instances of your app to speed up performance, or relaunch your app on a bigger server when it becomes popular. How should you ensure that your app can find and use its data trail along the way?

Shiny Server developer Jeff Allen explains the best ways to share data between sessions in Share data across sessions with ShinyApps.io, a new article at the Shiny Dev Center.

Want to see who is using your Shiny apps and what they are doing while they are there?

Google Analytics is a popular way to track traffic to your website. With Google Analytics, you can see what sort of person comes to your website, where they arrive from, and what they do while they are there.

Since Shiny apps are web pages, you can also use Google Analytics to keep an eye on who visits your app and how they use it.

Add Google Analytics to a Shiny app is a new article at the Shiny dev center that will show you how to set up analytics for a Shiny app. Some knowledge of jQuery is required.

Shiny v0.10.1 has been released to CRAN. You can either install it from a CRAN mirror, or update it if you have installed a previous version.

install.packages('shiny', repos = 'http://cran.rstudio.com')
# or update your installed packages
# update.packages(ask = FALSE, repos = 'http://cran.rstudio.com')

The most prominent change in this patch release is that we added full Unicode support on Windows. Shiny apps running on Windows must use the UTF-8 encoding for ui.R and server.R (also the optional global.R, README.md, and DESCRIPTION) if they contain non-ASCII characters. See this article for details and examples: http://shiny.rstudio.com/articles/unicode.html

Chinese characters in a shiny app

Chinese characters in a shiny app

Please note although we require UTF-8 for the app components, UTF-8 is not a general requirement for any other files. If you read/write text files in an app, you are free to use any encoding you want, e.g. you can readLines('foo.txt', encoding = 'Windows-1252'). The article above has explained it in detail.

Other changes include:

  • runGitHub() also allows the 'username/repo' syntax now, which is equivalent to runGitHub('repo', 'username'). (#427)
  • navbarPage() now accepts a windowTitle parameter to set the web browser page title to something other than the title displayed in the navbar.
  • Added an inline argument to textOutput(), imageOutput(), plotOutput(), and htmlOutput(). When inline = TRUE, these outputs will be put in span() instead of the default div(). This occurs automatically when these outputs are created via the inline expressions (e.g. `r renderText(expr)`) in R Markdown documents. See an R Markdown example at http://shiny.rstudio.com/gallery/inline-output.html (#512)
  • Added support for option groups in the select/selectize inputs. When the choices argument for selectInput()/selectizeInput() is a list of sub-lists and any sub-list is of length greater than 1, the HTML tag <optgroup> will be used. See an example at here (#542)

Please let us know if you have any comments or questions.

RStudio is very pleased to announce the general availability of Shiny Server Pro 1.2.

Download a free 45 day evaluation of Shiny Server Pro 1.2

Shiny Server Pro 1.2 adds support for R Markdown Interactive Documents in addition to Shiny applications. Learn more about Interactive Documents by registering for the Reproducible Reporting webinar August 13 and Interactive Reporting webinar September 3.

We are excited about the new ways in which you can now share your data analysis in Shiny Server Pro along with the security, management and performance tuning capabilities you and your IT teams need to scale.

Uncover all the features of Shiny Server Pro 1.2 in the updated Shiny Server admin guide…then give it a try!

We’ve added a new section of articles to the Shiny Development Center. These articles explain how to create interactive documents with Shiny and R Markdown.

You’ll learn how to

  • Use R Markdown to create reproducible, dynamic reports. R Markdown offers one of the most efficient workflows for writing up your R results.

  • Create interactive documents and slideshows by embedding Shiny elements into an R Markdown report. The Shiny + R Markdown combo does more than just enhance your reports; R Markdown provides one of the quickest ways to make light weight Shiny apps.

  • Take advantage of RStudio’s built in features that support R Markdown

interactive-articles.001

Learn more at shiny.rstudio.com/articles

The RStudio team recently rolled out new capabilities in RStudio, shiny, ggvis, dplyr, knitr, R Markdown, and packrat. The “Essential Tools for Data Science with R” free webinar series is the perfect place to learn more about the power of these R packages from the authors themselves.

Click to learn more and register for one or more webinar sessions. You must register for each separately. If you miss a live webinar or want to review them, recorded versions will be available to registrants within 30 days.

The Grammar and Graphics of Data Science
Live! Wednesday, July 30 at 11am Eastern Time US  Click to register

  • dplyr: a grammar of data manipulation – Hadley Wickham
  • ggvis: Interactive graphics in R – Winston Chang

Reproducible Reporting 
Live! Wednesday, August 13 at 11am Eastern Time US  Click to register

  • The Next Generation of R Markdown – Jeff Allen
  • Knitr Ninja – Yihui Xie
  • Packrat – A Dependency Management System for R – J.J. Allaire & Kevin Ushey

Interactive Reporting
Live! Wednesday, September 3 at 11am Eastern Time US  Click to register

  • Embedding Shiny Apps in R Markdown documents – Garrett Grolemund
  • Shiny: R made interactive – Joe Cheng

 

RStudio will teach the new essentials for doing data science in R at this year’s Strata NYC conference, Oct 15 2014.

R Day at Strata is a full day of tutorials that will cover some of the most useful topics in R. You’ll learn how to manipulate and visualize data with R, as well as how to write reproducible, interactive reports that foster collaboration. Topics include:

9:00am – 10:30am
A Grammar of Data Manipulation with dplyr
Speaker: Hadley Wickham

11:00am – 12:30pm
A Reactive Grammar of Graphics with ggvis
Speaker: Winston Chang

1:30pm – 3:00pm
Analytic Web Applications with Shiny
Speaker: Garrett Grolemund

3:30pm – 5:00pm
Reproducible R Reports with Packrat and Rmarkdown
Speaker: JJ Allaire & Yihui Xie

The tutorials are integrated into a cohesive day of instruction. Many of the tools that we’ll cover did not exist six months ago, so you are almost certain to learn something new. You will get the most out of the day if you already know how to load data into R and have some basic experience visualizing and manipulating data.

Visit strataconf.com/stratany2014 to learn more and register! Early bird pricing ends July 31.

Not available on October 15? Check out Hadley’s Advanced R Workshop in New York City on September 8 and 9, 2014.

 

Shiny v0.10 comes with a quick, handy guide. Use the Shiny cheat sheet as a quick reference for building Shiny apps. The cheat sheet will guide you from structuring your app, to writing a reactive foundation with server.R, to laying out and deploying your app.

 

cheatsheet

 

You can find the Shiny cheat sheet along with many more resources for using Shiny at the Shiny Dev Center, shiny.rstudio.com.

(p.s. Visit the RStudio booth at useR! today for a free hard copy of the cheat sheet.)

Follow

Get every new post delivered to your Inbox.

Join 12,252 other followers