Shiny Application: A shaded Normal Distribution

I have played a bit with shiny. The RStudio folks provides the possibility of deploying R “Shiny” applications on their server. The final result  which will look a lot like this: https://<YourAccount>.shinyapps.io/<YourApp>. There are several plans for this type of deployment, including one that allows you to deploy up to 5 applications for free.

You can sign up using on www.shinyapps.io creating a new account or logging in using your github.com or gmail account. The most recent version of Shiny does no longer require two separate files as I was reporting in the last article on the subject. Now you can condense all the functionality in a single file: app.R.  In synthesis, you need to build a app.R file that contains the following:

  • The inclusion of the shiny library: library(shiny)
  • A ui function: ui <-fluidPage(….
    • This will define your page layout and your controls
  • A server function: server <- function(input, output) {
    • This will be your server logic
  • A call to shinyApp(ui=ui, server=server )
    • This is the glue that puts everything together

When building your application in RStudio, it recognizes it as a “Shiny” application and it lets run it in your browser, in a separate window or in the plot pane. It also shows a “Publish” button that allows you to upload the application to the www.shinyapps,io website. This you can do provided that you have set up an account.

To learn the basics, I have used the tutorials and the shiny app gallery that you can find at http://shiny.rstudio.com/gallery/. Almost all examples include a link to or a pane with the source code.

As far as the application, I have borrowed some code from this article on r-bloggers.com.  This is in relation with a swirl() problem on two of the classes of the Statistical Inference course on Coursera.

The shiny app I propose can be found at this link: Shaded Normal Distribution.  It does much less than the original shadenorm() function by Tony Cookson did, I tried to leave all the nice use cases that he proposed as comments in the code. This is a screenshot, You will find all the source code below it: