17 Dec 2016

LMGTFY: What is an app?

What is an app?

Our approach to create an online app

  • use a framework (shiny)
  • use widgets (htmlwidgets)
  • seperation of concerns (ui, server, custom R functions)

What is a shiny app?

3 files that live in the same folder

  1. ui.R (Web Graphical user interface, looks good.)
  2. server.R (backend, does the work)
  3. global.R (globally available objects) (optional)

=> let's build our first app!

What does the shiny framework do for us?

  • create HTML/CSS/Javascript code
  • start/run a (local) webserver
  • communication between the R session and the browser

Analyzing the hello-world app: ui.R

library(shiny)
shinyUI(fluidPage(
  titlePanel("A random normal"),
  # Sidebar with a slider input for number of bins 
  sidebarLayout(
    sidebarPanel(
       sliderInput("obs",
                   "Number of obs:",
                   min = 1,
                   max = 1000,
                   value = 100)
    ),
    mainPanel(
       plotOutput("randomPlot")
    )
  )
))

A minimal note on HTML

  • Markup language
  • content is wrapped in tags
<a href="http://somedestination.com">some link</a>
<b>this is bold</b>
<i>this is italic</i>
<div class="some-class">a class with a style</div>

=> shiny functions create these wraps for us.

Analyzing the hello-world app: server.R

shinyServer(function(input, output) {
    output$randomPlot <- renderPlot({
    hist(rnorm(input$obs),
         col = 'darkgray',
         border = 'white')
  })
})

Deployment

  • local
  • shiny server
  • SaaS

Are you ready for to build a real app?

Planning the app

This course: dashboard structure

  • sidebar
  • topbar
  • main panel
  • menu buttons / sub pages

The shinydashboard package

library(shinydashboard)
dashboardPage(
  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody()
)

An shiny based personality test

  • Find items, e.g., sapa project
  • organize items, demographics, analytics
  • Which tools, widgets are needed?