My first... web application with Shiny

It was several time I was thinking about developing a web application with R and Shiny.

In these days I realize my first application with Shiny. You can find it at http://spark.rstudio.com/nsturaro/pyramid0/

The idea is very simple: I plot a population pyramid for Italy. Data refers to year 2002 through 2011. Ages can be aggregated into classes, specifying the width of classes.

A Shiny application is defined by two R files: ui.R and server.R. As the names suggest, ui.R contains definition of the application interface, while server.R contains definition of the computation behind.

Let see the scripts.

ui.R contains the shiny package requirements and then call the shinyUI() function. Inside this function, the pageWithSidebar() function is used to specify which layout should be used. Finally, three elements are built, by just as many functions: headerPanel() contains the main title, sidebarPanel() defines the sidebar and mainPanel() defines the main content of the web page.

The sidebar panel contains two sliders and some custom HTML codes useful to put the company logo. The main panel contains only the plot.

This is the full code:

On the other side, server.R contains the R code to produce the pyramid plot. Code that read input values and return output ought be wrapped in a function, contained in the shinyServer() function.

10
Shares
This entry was posted in R and tagged , , . Bookmark the permalink.

Leave a Reply