cat_r_file <- function(file){
  cat("```R", readLines(file), "```", sep = "\n")  
}

Shiny modules make it much easier to design and build complex shiny apps.

Imagine that you are designing an app that requires the user to upload a csv file to be parsed into a data frame. You will wish to use the data frame elsewhere in the app. Instead of writing the parser from scratch, you can use a set of shinypod functions in your app.

Shinypod is simply an implementaton of a set of design guidelines to allow you to use, remix, and even build your own shiny modules. An advantage of using such guidelines is that we can all use each others' shinypods more quickly and reliably.

Before getting started, you are referred to RStudio's article on shiny modules.

First example - CSV parser

This package, shinypod, offers functions that you can use to put a CSV parser into your app.

Let's look at a ui.R file:

cat_r_file(system.file("shiny", "read_delim", "ui.R", package = "shinypod"))

And a server.R file:

cat_r_file(system.file("shiny", "read_delim", "server.R", package = "shinypod"))

For this implementation we call upon three functions.

The first two functions each return a named shiny::tagList of UI elements that can be used in a sidebar layout. The side panel contains the inputs, and the main panel contains the outputs.

Other UI arrangements are possible; you are referred to the "remixing-shinypods" vignette.

The third function is used in the server function to return a reactive element. This reactive returns the parsed dataframe.

To use all three, all you have to do is call each of the three functions using the same id, in this case "csv" - this is to keep the shiny namespace tidy.

If you like, try out the deployed app.

Second example - CSV parser with dygraph

In this example, we will look at what you can do by combining shinypods. Here, we will combine the pod used to parse a csv with a pod used to build a dygraph.

Dygraphs are especially handy for visualizing time series. Often, time-series data may be available in a data frame (parsed from a csv), and we wish to visualize it. This is where we would use a set of dygraphs functions from shinypod.

We can build onto our previous example by adding a dyraph shinypod.

Let's look at a ui.R file:

cat_r_file(system.file("shiny", "read_delim_dygraph", "ui.R", package = "shinypod"))

And a server.R file:

cat_r_file(system.file("shiny", "read_delim_dygraph", "server.R", package = "shinypod"))

A few things to note:

If you like, try out the deployed app.



ijlyttle/shinypod documentation built on May 18, 2019, 3:41 a.m.