25 Nov 2016

:~$ whoami

Matthias Bannert

  • studied economics @UniKN
  • PhD @ETHZ: partly economics, mostly methodology and stats
  • currently: develops software for academic researchers @ETHZ
  • open source software projects: timeseriesdb, dropR, RAdwords
matthias bannert

About this course

"Use the R ecosystem effectively to build useful web apps and visualizations."


Approach

  • planning (seperation of concerns)
  • framework
  • widgets

>> course material

Inspiration

matthias bannert

Inspiration

matthias bannert

Inspiration

Before you start…

… check the stack:

  • R 3.3.1+
  • R Studio 1.0+
  • R packages: shiny, shinydashboard, knitr
  • git (optional)

Guess what…

… the following code does:

a <- 1+1
b <- 2+2
d <- a + b
e <- c(1,2,4)

You got this right, don't you?

a <- 1+1
b <- 2+2
d <- a + b
e <- c(1,2,4)
## [1] 2
## [1] 4
## [1] 6
## [1] 1 2 4

Guess what…

… the following code does:

m <- matrix(1:12,4,3)
d <- data.frame(col1 = 1:8,
                col2 = letters[1:8])
l <- list()
l$element_a <- a
l$element_m <- m
l$element_d <- d

You got this right, don't you?

m <- matrix(1:12,4,3)
##      [,1] [,2] [,3]
## [1,]    1    5    9
## [2,]    2    6   10
## [3,]    3    7   11
## [4,]    4    8   12

You got this right, don't you?

d <- data.frame(col1 = 1:8,
                col2 = letters[1:8])
##   col1 col2
## 1    1    a
## 2    2    b
## 3    3    c
## 4    4    d
## 5    5    e
## 6    6    f
## 7    7    g
## 8    8    h

You got this right, don't you?

l <- list()
l$element_a <- a
l$element_m <- m
l$element_d <- d
## $element_a
## [1] 2
## 
## $element_m
##      [,1] [,2] [,3]
## [1,]    1    5    9
## [2,]    2    6   10
## [3,]    3    7   11
## [4,]    4    8   12
## 
## $element_d
##   col1 col2
## 1    1    a
## 2    2    b
## 3    3    c
## 4    4    d
## 5    5    e
## 6    6    f
## 7    7    g
## 8    8    h

You know all of those, don't you?

?sum()
ls()
c()
matrix()
data.frame()
list()
head()
tail()
str()
function()
lapply()

Are you familiar with your R Studio IDE?

  • .Rproj
  • script window
  • console
  • file browser

Some introductory resources

Getting started with shiny

3 files that live in one folder

  • ui.R (User Interface)
  • server.R (Backend / Processing / Computation)
  • global.R (optional, data etc.)

Organize your UI - the dashboard package

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    sidebarMenu()
  ),
  # Body of the App #############
  dashboardBody(
    tabItems()
  )
)

Add processing to your app

server <- function(input, output) {
  
  output$someplot <- renderPlot({
    hist(rnorm(input$N))
  })
  
}

Shiny Deployment

Shiny resources

Ideas for Apps ?

  • Want to do something interactive for teaching stats?
  • Want to give an existing application a GUI?
  • Have a personal project?