I've been
playing around for a bit with r shiny for the last couple of days.
I think it
is important to understand some concept relating to r shiny.
First of
all, it is important to understand that an r shiny application is divided into
three files:
·
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 this library allowed to create interactive app
and not just dashboard.
As I
previously said our 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 date user input interface
·
Two
Say were the output of server.R will be displayed
·
To
Control the general appearance of the application.
What I
found a bit tricky is to reference the input and the output between
server.r and iu.r.
Here is a
quick explanation:
The user
input that will be programmed in iu.r will then be used in server.r. The
general syntax in order to use the user input in server.org is input$input_name.
The same
goes for the outputs. In server.r will refer to the output as output$output_name.
The syntax
to refer to input and output in ui.r is a bit different compare to server.r.
In order to
refer to an input in iu.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)
And here is how that user input will be used in server.r
t = data.frame(Comments
= input$Comments )
This is a
text to refer to an output in ui.r is also different compared to server.r
For example
here is the syntax to output a table :
tableOutput('contents')
In server
dot R the syntax to create that output is as follows:
output$contents
<- renderTable({
Syntax to
create your output …
})
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
true Shiny Connect.
Commentaires
Enregistrer un commentaire