R Shiny is a web application framework for R that allows users to create interactive web apps. Shiny apps have two components: a user interface script that controls layout and appearance, and a server script that contains the code needed to build the app. No knowledge of HTML, JavaScript or CSS is required to use Shiny, though knowing some of these languages can make apps more interesting. Getting started requires installing the Shiny package and creating two R scripts, ui.R and server.R, that define the user interface and server logic. Widgets like sliders and text inputs can be added to collect user input and interact with analyses. Shiny makes it easy to share live and explorable analyses by integrating R with web pages
3. What is R shiny?
A web application framework for R that allows
you to turn your
data into an interactive web App.
You can easily integrate R with webpage.
Suppose you want your web page run machine
learning algorithms like random forest, SVM
etc and display summary of the model with
the flexibility of selecting inputs from user.
Shiny can do it very easily.
4. How does it work?
Shiny apps have two components:
- user interface script (controls layout and appearance by
converting R code into HTML)
- server script (contains the code needed to build the app)
6. How does it work?
• ui - nested R functions that assemble an
HTML user interface for your app
• server - a function with instructions on how
to build and rebuild the R objects displayed
in the UI
• shinyApp - combines ui and server into
an app. Wrap with runApp() if calling from a
sourced script or inside a function
7. Do I need to know how to code in HTML?
No knowledge of HTML, JavaScript or CSS is required. However, you
can make your apps more interesting if you know some HTML codes.
There are some excellent tutorials and lots of links for more
information at http://shiny.rstudio.com/
9. Getting Started:
> install.packages("shiny")
> library(shiny)
> runApp("my_app")
As a minimum, every shiny app has two R scripts (named ui and server) saved within the same
directory (e.g. “my_app”).
10. Getting Started:
The fluidPage function allows the display to adjust
automatically to the browser dimensions.
The unnamed function contains the
code needed to run the app.
11. Getting Started:
The fluidPage function allows the display to adjust
automatically to the browser dimensions.
The unnamed function contains the
code needed to run the app.
Other scripts (written in standard R code), libraries and data can be called by the
server script if they are needed, using standard R commands above the shiny Server function.
12. The User Interface (ui.R)
A series of nested shiny functions control
the layout of the content. sidebarLayout is
a function with two compulsory arguments,
both themselves functions (sidebarPanel
and mainPanel). An optional argument
controls the position of the panels. Text is
written as a character string inside
quotation marks.
# ui.R
shinyUI(fluidPage(
titlePanel("title panel"),
sidebarLayout(position = "right",
sidebarPanel( "sidebar panel"),
mainPanel("main panel")
)
))
13. The User Interface (ui.R)
# ui.R
shinyUI(fluidPage(
titlePanel("title panel"),
sidebarLayout(position = "right",
sidebarPanel( "sidebar panel"),
mainPanel("main panel")
)
))
14. Building an App :
Complete the template by adding arguments to fluidPage() and a
body to the server function :
15. Building an App :
Save your template as app.R. Alternatively, split your template into two files named ui.R and server.R.
16. Adding Widgets
Widgets are interactive web elements. A series of inbuild shiny functions allows widgets to be
easily added to webpages. Each function has several arguments. It must have at least a name
(used to access its value, but not visible) and a label (visible on the page). Both are character
strings. Other arguments are widget specific.
21. Why Shiny?
Shiny is easy and powerful
• You can make your analyses Shared, Live and explorable
• It’s going to get more powerful - interactive
graphics like d3 are coming
• You can get support from the community and RStudio
• Start coding - and show us what you can achieve