Developing Data
Products
A DEMO ON SHINY
IDA MOOC
TOH WEI ZHONG
SEPTEMBER 2015
A little bit about me
Graduated from NUS, Computational Biology
◦ Statistics and computing onto biology and healthcare
◦ E.g. –omics
Data Scientist in NCS
◦ Smart Nation projects (defense and public safety)
Agenda for this evening
An introduction to shiny
◦ What is it about?
◦ Motivation
Basic concepts
A quick coding demo
An introduction to
shiny
Shiny: Web application
framework for R
Web application: any software application in which the client runs in a
web browser
Can be constructed from a variety of languages and APIs
◦ HTML, CSS, JavaScript
◦ Ruby, Ruby on Rails, PHP, etc. etc.
R and web applications?
What’s the link?
Science / communications
◦ Data visualization
◦ Interactivity on results
◦ E.g. Imagine scientific publications having a simple app to communicate
results – phenomenon like autism/anti-vax shouldn’t even occur
◦ Compared to a static report / paper
R and web applications?
What’s the link?
Industrial
◦ POC (to sell analytics, dashboard as endpoint)
◦ Sell
◦ “Tableau cannot do this type of modelling.”
◦ “SAS cannot do this type of visualization.”
◦ “We can.”
◦ “Wow!” factor
◦ Show senior mgmt. {deck + code} or {deck + app}?
My personal examples
Condensed to a simple and
intuitive UI
Use-cases
Q&A engine – “Ask a Doctor”
Call center dashboard (call volumes, repeated queries (market basket
analysis), agent performances)
… anything with analytics as frontend, shiny can serve as backend
Basic concepts
Server.R and UI.R
Shiny apps fundamentally have 2
components
◦ Server.R
◦ UI.R
Server.R consists all R commands
to be executed in the app
UI.R dictates how the UI appears
UI.R
The simpler half of the pair (Server.R and UI.R)
Has total control over how the UI looks like
Some of the things you can add:
◦ Text and images
◦ Sliderbars
◦ Radio buttons
◦ Checkboxes
◦ Hyperlinks
UI.R
shinyUI(fluidPage(
titlePanel(“This is the title”),
mainPanel(
tabsetPanel(
tabPanel(“One”),
tabPanel(“Two”)
)
)
))
UI.R
shinyUI(fluidPage(
titlePanel(“This is the title”),
mainPanel(
tabsetPanel(
tabPanel(“One”,
sliderInput("id", "This is a slider", min = 1, max =
10, value = 5))),
tabPanel(“Two”)
)
)
))
User input
Each time we add a UI component that takes in input, we assign it to an
ID.
The definition of the UI component includes an ID, which we define, eg.
◦ sliderInput("id1", "This is a slider", min = 1, max = 10, value = 5)))
◦ checkboxInput(“id2”, “Check this?”, TRUE)
◦ radioButtons(“id3”, “Which one?", c(“This”= “this”, “That” = “that”)
Server.R
What server.R does is to take all the inputs from the user (via the UI
components), and execute the necessary
Essentially, the basic task of server.R is to define the relationship
between the inputs and outputs
shinyServer(function(input,output){
output$plot <- renderPlot({
boxplot(mtcars[,input$id3])
})
})
shinyUI(fluidPage(
titlePanel("This is the title"),
mainPanel(
tabsetPanel(
tabPanel("One",
sliderInput("id", "This is a slider", min = 1, max = 10, value = 5),
checkboxInput("id2", "Check this?", TRUE),
radioButtons("id3", "Which variable of mtcars?", c("mpg"= "mpg", "disp" =
"disp")),
plotOutput("plot")),
tabPanel("Two")
)
)
))
Server.R
UI.R
What’s happening?
1. User select which radio button
2. User’s option is stored in “id3”
3. Server.R takes the value of “id3”, use it to generate a boxplot (render)
4. Generating and surfacing the boxplot are two different steps. To
surface the boxplot on the UI, UI.R output the boxplot
Server.R Generate Render (renderPlot, renderTable)
UI.R Surface / actualize Output (plotOutput, tableOutput)
Coding demo
Tab panels
Slider bars
File import
Hyperlinks
Checkboxes
Radio
buttons
Images
Main & Sidebar panels
Text
Table output
Thanks!
Questions?
HTTP://SHINY.RSTUDIO.COM/GALLERY/
HTTPS://GITHUB.COM/TOHWEIZHONG/IDA-MOOC-SHINY
TOHWEIZHONG@HOTMAIL.COM
HTTPS://SG.LINKEDIN.COM/IN/TOHWEIZHONG

An R shiny demo for IDA MOOC facilitation, Developing Data Products

  • 1.
    Developing Data Products A DEMOON SHINY IDA MOOC TOH WEI ZHONG SEPTEMBER 2015
  • 2.
    A little bitabout me Graduated from NUS, Computational Biology ◦ Statistics and computing onto biology and healthcare ◦ E.g. –omics Data Scientist in NCS ◦ Smart Nation projects (defense and public safety)
  • 3.
    Agenda for thisevening An introduction to shiny ◦ What is it about? ◦ Motivation Basic concepts A quick coding demo
  • 4.
  • 5.
    Shiny: Web application frameworkfor R Web application: any software application in which the client runs in a web browser Can be constructed from a variety of languages and APIs ◦ HTML, CSS, JavaScript ◦ Ruby, Ruby on Rails, PHP, etc. etc.
  • 6.
    R and webapplications? What’s the link? Science / communications ◦ Data visualization ◦ Interactivity on results ◦ E.g. Imagine scientific publications having a simple app to communicate results – phenomenon like autism/anti-vax shouldn’t even occur ◦ Compared to a static report / paper
  • 7.
    R and webapplications? What’s the link? Industrial ◦ POC (to sell analytics, dashboard as endpoint) ◦ Sell ◦ “Tableau cannot do this type of modelling.” ◦ “SAS cannot do this type of visualization.” ◦ “We can.” ◦ “Wow!” factor ◦ Show senior mgmt. {deck + code} or {deck + app}?
  • 8.
  • 10.
    Condensed to asimple and intuitive UI
  • 14.
    Use-cases Q&A engine –“Ask a Doctor” Call center dashboard (call volumes, repeated queries (market basket analysis), agent performances) … anything with analytics as frontend, shiny can serve as backend
  • 15.
  • 16.
    Server.R and UI.R Shinyapps fundamentally have 2 components ◦ Server.R ◦ UI.R Server.R consists all R commands to be executed in the app UI.R dictates how the UI appears
  • 17.
    UI.R The simpler halfof the pair (Server.R and UI.R) Has total control over how the UI looks like Some of the things you can add: ◦ Text and images ◦ Sliderbars ◦ Radio buttons ◦ Checkboxes ◦ Hyperlinks
  • 18.
    UI.R shinyUI(fluidPage( titlePanel(“This is thetitle”), mainPanel( tabsetPanel( tabPanel(“One”), tabPanel(“Two”) ) ) ))
  • 19.
    UI.R shinyUI(fluidPage( titlePanel(“This is thetitle”), mainPanel( tabsetPanel( tabPanel(“One”, sliderInput("id", "This is a slider", min = 1, max = 10, value = 5))), tabPanel(“Two”) ) ) ))
  • 20.
    User input Each timewe add a UI component that takes in input, we assign it to an ID. The definition of the UI component includes an ID, which we define, eg. ◦ sliderInput("id1", "This is a slider", min = 1, max = 10, value = 5))) ◦ checkboxInput(“id2”, “Check this?”, TRUE) ◦ radioButtons(“id3”, “Which one?", c(“This”= “this”, “That” = “that”)
  • 21.
    Server.R What server.R doesis to take all the inputs from the user (via the UI components), and execute the necessary Essentially, the basic task of server.R is to define the relationship between the inputs and outputs
  • 22.
    shinyServer(function(input,output){ output$plot <- renderPlot({ boxplot(mtcars[,input$id3]) }) }) shinyUI(fluidPage( titlePanel("Thisis the title"), mainPanel( tabsetPanel( tabPanel("One", sliderInput("id", "This is a slider", min = 1, max = 10, value = 5), checkboxInput("id2", "Check this?", TRUE), radioButtons("id3", "Which variable of mtcars?", c("mpg"= "mpg", "disp" = "disp")), plotOutput("plot")), tabPanel("Two") ) ) )) Server.R UI.R
  • 24.
    What’s happening? 1. Userselect which radio button 2. User’s option is stored in “id3” 3. Server.R takes the value of “id3”, use it to generate a boxplot (render) 4. Generating and surfacing the boxplot are two different steps. To surface the boxplot on the UI, UI.R output the boxplot Server.R Generate Render (renderPlot, renderTable) UI.R Surface / actualize Output (plotOutput, tableOutput)
  • 25.
  • 26.
    Tab panels Slider bars Fileimport Hyperlinks Checkboxes Radio buttons Images Main & Sidebar panels Text
  • 27.
  • 28.