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

The dygraphs package is an R interface to the dygraphs JavaScript charting library. It provides rich facilities for charting time-series data in R, including:

  • Automatically plots xts time-series objects (or objects convertible to xts).
  • Rich interactive features including zoom/pan and series/point highlighting.
  • Highly configurable axis and series display (including optional 2nd Y-axis).
  • Display upper/lower bars (e.g. prediction intervals) around series.
  • Various graph overlays including shaded regions, event lines, and annotations.
  • Use at the R console just like conventional R plots (via RStudio Viewer).
  • Embeddable within R Markdown documents and Shiny web applications.

The dygraphs package is available on CRAN now and can be installed with:

install.packages("dygraphs")

Examples

Here are some examples of interactive time series visualizations you can create with only a line or two of R code (the screenshots are static, click them to see the interactive version).

Panning and Zooming

This code adds a range selector that’s can be used to pan and zoom around the series data:

dygraph(nhtemp, main = "New Haven Temperatures") %>%
  dyRangeSelector()

Screen Shot 2015-04-09 at 1.01.35 PM

Point Highlighting

When you hover over the time-series the values of all points at the location of the mouse are shown in the legend:

lungDeaths <- cbind(ldeaths, mdeaths, fdeaths)
dygraph(lungDeaths, main = "Deaths from Lung Disease (UK)") %>%
  dyOptions(colors = RColorBrewer::brewer.pal(3, "Set2"))

Screen Shot 2015-04-09 at 12.53.54 PM

Shading and Annotations

There are a wide variety of tools available to annotate time series. Here we demonstrate creating shaded regions:

dygraph(nhtemp, main="New Haven Temperatures") %>% 
  dySeries(label="Temp (F)", color="black") %>%
  dyShading(from="1920-1-1", to="1930-1-1", color="#FFE6E6") %>%
  dyShading(from="1940-1-1", to="1950-1-1", color="#CCEBD6")

Screen Shot 2015-04-09 at 1.11.31 PM

You can find additional examples and documentation on the dygraphs for R website.

Bringing JavaScript to R

One of the reasons we are excited about dygraphs is that it takes a mature and feature rich visualization library formerly only accessible to web developers and makes it available to all R users.

This is part of a larger trend enabled by the htmlwidgets package, and we expect that more and more libraries like dygraphs will emerge over the coming months to bring the best of JavaScript data visualization to R.

 

action-button

Action buttons can be tricky to use in Shiny because they work differently than other widgets. Widgets like sliders and select boxes maintain a value that is easy to use in your code. But the value of an action button is arbitrary. What should you do with it? Did you know that you should almost always call the value of an action button from observeEvent() or eventReactive()?

The newest article at the Shiny Development Center explains how action buttons work, and it provides five useful patterns for working with action buttons. These patterns also work well with action links.

Read the article here.

RStudio is excited to announce the general availability (GA) of shinyapps.io.

Shinyapps.io is an easy to use, secure, and scalable hosted service already being used by thousands of professionals and students to deploy Shiny applications on the web. Effective today, shinyapps.io has completed beta testing and is generally available as a commercial service for anyone.

As regular readers of our blog know, Shiny is a popular free and open source R package from RStudio that simplifies the creation of interactive web applications, dashboards, and reports. Until today, Shiny Server and Shiny Server Pro were the most popular ways to share shiny apps. Now, there is a commercially supported alternative for individuals and groups who don’t have the time or resources to install and manage their own servers.

We want to thank the nearly 8,000 people who created at least one shiny app and deployed it on shinyapps.io during its extensive alpha and beta testing phases! The service was improved for everyone because of your willingness to give us feedback and bear with us as we continuously added to its capabilities.

For R users developing shiny applications that haven’t yet created a shinyapps.io account, we hope you’ll give it a try soon!  We did our best to keep the pricing simple and predictable with Free, Basic, Standard, and Professional plans. Each paid plan has features and functionality that we think will appeal to different users and can be purchased with a credit card by month or year. You can learn more about shinyapps.io pricing plans and product features on our website.

We hope to see your shiny app on shinyapps.io soon!

Great news for Shiny and R Markdown enthusiasts!

An Interactive Reporting Workshop with Shiny and R Markdown is coming to a city near you. Act fast as only 20 seats are available for each workshop.

You can find out more / register by clicking on the link for your city!

East Coast West Coast
March 2 – Washington, DC April 15 – Los Angeles, CA
March 4 – New York, NY April 17 – San Francisco, CA
March 6 – Boston, MA April 20 – Seattle, WA

You’ll want to take this workshop if…

You have some experience working with R already. You should have written a number of functions, and be comfortable with R’s basic data structures (vectors, matrices, arrays, lists, and data frames).

You will learn from…

The workshop is taught by Garrett Grolemund. Garrett is the Editor-in-Chief of shiny.rstudio.com, the development center for the Shiny R package. He is also the author of Hands-On Programming with R as well as Data Science with R, a forthcoming book by O’Reilly Media. Garrett works as a Data Scientist and Chief Instructor for RStudio, Inc. GitHub

Shiny version 0.11 is available now! Notable changes include:

  • Shiny has migrated from Bootstrap 2 to Bootstrap 3 for its web front end. More on this below.
  • The old jsliders have been replaced with ion.rangeSlider. These sliders look better, are easier for users to interact with, and support updating more fields from the server side.
  • There is a new passwordInput() which can be used to create password fields.
  • New observeEvent() and eventReactive() functions greatly streamline the use of actionButton and other inputs that act more like events than reactive inputs.

For a full set of changes, see the NEWS file. To install, run:

install.packages("shiny")

We’ve also posted an article with notes on upgrading to 0.11.

Bootstrap 3 migration

In all versions of Shiny prior to 0.11, Shiny has used the Bootstrap 2 framework for its web front-end. Shiny generates HTML that is structured to work with Bootstrap, and this makes it easy to create pages with sidebars, tabs, dropdown menus, mobile device support, and so on.

The Bootstrap development team stopped development on the Bootstrap 2 series after version 2.3.2, which was released over a year ago, and has since focused their efforts on Bootstrap 3. The new version of Bootstrap builds on many of the same underlying ideas, but it also has many small changes – for example, many of the CSS class names have changed.

In Shiny 0.11, we’ve moved to Bootstrap 3. For most Shiny users, the transition will be seamless; the only differences you’ll see are slight changes to fonts and spacing.

If, however, you customized any of your code to use features specific to Bootstrap 2, then you may need to update your code to work with Bootstrap 3 (see the Bootstrap migration guide for details). If you don’t want to update your code right away, you can use the shinybootstrap2 package for backward compatibility with Bootstrap 2 – using it requires adding just two lines of code. If you do use shinybootstrap2, we suggest using it just as an interim solution until you update your code for Bootstrap 3, because Shiny development going forward will use Bootstrap 3.

Why is Shiny moving to Bootstrap 3? One reason is support: as mentioned earlier, Bootstrap 2 is no longer developed and is no longer supported. Another reason is that there is dynamic community of actively-developed Bootstrap 3 themes. (Themes for Bootstrap 2 also exist, but there is less development activity.) Using these themes will allow you to customize the appearance of a Shiny app so that it doesn’t just look like… a Shiny app.

We’ve also created a package that make it easy to use Bootstrap themes: shinythemes. Here’s an example using the included Flatly theme: flatly

See the shinythemes site for more screenshots and instructions on how to use it.

We’re also working on shinydashboard, a package that makes it easy to create dashboards. Here’s an example dashboard that also uses the leaflet package.

buses

The shinydashboard package still under development, but feel free to try it out and give us feedback.

RStudio is happy to announce the availability of the shinyapps.io beta.

Shinyapps.io is an easy to use, secure, and scalable hosted service already being used by thousands of professionals and students to deploy Shiny applications on the web. Today we are releasing a significant upgrade as we transition from alpha to beta, the final step before general availability (GA) later this quarter.

New Feature Highlights in shinyapps.io beta

  • Secure and manage authorized users with support for new authentication systems, including Google, GitHub, or a shinyapps.io account.
  • Tune application performance by controlling the resources available. Run multiple R processes per application instance and add application instances.
  • Track performance metrics and simplify application management in a new shinyapps.io dashboard. See an application’s active connections, CPU, memory, and network usage. Review application logs, start, stop, restart, rebuild and archive applications all from one convenient place.

During the beta period, these and all other features in shinyapps.io are available at no charge. At the end of the beta, users may subscribe to a plan of their choice or transition their applications to the free plan.

If you do not already have an account, we encourage anyone developing Shiny applications to consider shinyapps.io beta and appreciate any and all feedback on our features or proposed packaging and pricing.

Happy New Year!

 

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.

Follow

Get every new post delivered to your Inbox.

Join 17,612 other followers