Transcript Shiny in R

shiny in R
the fundamentals of getting started
What Is It?
• New package in R to create web apps
• Web app built entirely in R, but can also incorporate HTML, CSS,
and JavaScript for more flexibility
• By default, the UI is simple to create and view
• Built-in widgets for displaying plots, tables, and any other printed
output from R
2
Simple Example
> runExample("01_hello")
3
ui.R & server.R
• Two fundamental entities to any Shiny web app
• ui.R
• Designates the user interface of your app
• server.R
• Contains all the nuts and bolts of your app
4
The Flow
Start
ui.R
input$tag
output$tag
server.R
5
ui.R in Detail
• The three fundamental components of ui.R:
• headerPanel()
• sidebarPanel()
• selectInput()
• checkboxGroupInput()
• mainPanel()
6
ui.R Syntax
To be memorized!
7
The Flow
Start
ui.R
input$tag
output$tag
server.R
8
Dashboard Example
9
server.R in Detail – input$tag
• input$tag
• Whatever options are selected under
sidebarPanel() in ui.R is passed to the server.R
script
tag
• input$dataset becomes either “Products”,
“Clients”, or “All data” string, depending on which
one the user chooses
• input$dataset is reactionary, which means it
always changes each time the user decides to
select any new value
• Beware!! The $ in input$tag here does not refer to
any column in the input object
10
server.R in Detail – input$tag
(continued)
• What does input$dataset do?
• Anything you want to do with it
11
The Flow
Start
ui.R
input$tag
output$tag
input$dataset = “Products”
OR
input$dataset = “Clients”
server.R
OR
input$dataset = “All data”
12
server.R in Detail – output$tag
• ‘output’s themselves have tags!
tag
• The output is passed to ui.R and recognized under mainPanel()
tag
13
server.R Syntax
To be memorized!
14
Summary
• User chooses the inputs
• Inputs are stored in input$tags
• input$tags are manipulated in
server.R
• server.R returns output (tables,
charts, printed text etc.) in the form
of output$tags
• The output$tags from server.R is
then accepted by ui.R and displayed
on the dashboard for the user
15
Tips
•
•
•
•
Start small
Keep track of your parentheses
Work on ui.R first
Reference my cheatsheet
• github.com/alaneng/personal
• Frustration will be commonplace
• https://groups.google.com/forum/?fromgroups#!forum/shiny-discuss
Check out Glimmer -- host your web app online!
16
I didn’t understand anything
17
I’m for hire!
• [email protected]
• linkedin.com/in/alanfaieng
• github.com/alaneng/personal
• @alanengdata
18