Using R-Shiny
What is shiny in how is it structured?
Shiny is an R package that makes it easy to build interactive web apps straight from R.
Shiny applications have two components, a user interface object and a server function, that are passed as arguments to the shinyApp function that creates a Shiny app object from this UI/server pair.
Shiny components:
·APP.R will be used to launch the application
·SERVER.R will be used to define the application logic
·UI.R would be used to program the user interface of the application
I will give more details about these 3 files later.
It’s also helpful to understand that this library allows to create interactive app and not just dashboard. Although you can also create dashboard.
As I previously said a shiny application is divided into 3 files. Programming task is mainly divided between ui and server.
What is the use of UI.R? Basically it can be divided into 3 functions:
· To Program the user input interface
· Two Say were the output of SERVER.R will be displayed
· To control the general appearance of the application.
What could be a bit tricky is to reference the input and the output between SERVER.r and UI.R.
Here is a quick explanation:
The user input will be programmed in UI.R and then it will be used in SERVER.R. The general syntax in order to use the user input in SERVER.R is input$input_name.
The same goes for the outputs. In SERVER.R we will refer to the output as output$output_name.
The syntax for referring to input and output in UI.R is a bit different compare to SERVER.R.
In order to refer to an input in UI.R you have to put the name of the input as the the first argument to the input.
Here is an example for a text input :
textInput(‘Comments’, ‘add value’, value = “”, width = NULL, placeholder = NULL)
In this case the input will be referred as Comments.
Now that we have seen how it is done in UI.R, let’s see how we do it in SERVER.R.
In this case we want to implement the text input referred to as Comments.
T = data.frame(Comments = input$Comments )
Now that we have seen how do we reference the inputs let’s see how to reference the outputs
Let’s start to see how to do this in SERVER.R.
In this example we create a table which is referred by the name contents.
output$contents <- renderTable({
Syntax to create your output …
})
The syntax is also straight-forward in UI.R.
In this example we will display the table contents.
for example:
tableOutput(‘contents’)
In conclusion
I think it is quite easy to familiarize yourself with the syntax of R Shiny.
In conjunction with other R packages, I think it is possible to create pretty awesome application which R shiny.
Another field to explore is the deployment of shiny app. One way of doing that would be through Shiny Connect.