december 2015 meetup - shiny: make your r code interactive - craig wang

Post on 12-Apr-2017

299 Views

Category:

Data & Analytics

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Shiny: Make Your R Code Interactive

Craig Wang

MSc in Statistics at ETH

R Programmer at Institut für Mathematik UZH

Zurich R User Group Meetups December

1

Brief Demo

http://t.uzh.ch/se

2Zurich R User Group Meetups

December

Overview

• Introduction

• Setup and structure

• Work-through example

• Deploy and Share

• More Resources

3Zurich R User Group Meetups

December

Introduction to Shiny

• A freely-available third party R package created by Rstudio

• Allows to transform R code into interactive web applications

• Provide native programming environments

• Easy to get hands on, no website design experience required

4Zurich R User Group Meetups

December

Setup and Structure

• Simply install and load the package ‘shiny’

• Select a path to save all your files about your Shiny application

• Basic files• ui.R is a script file that implements all the user interface elements such as

buttons, drop-down menus, sliders

• server.R is a script file that takes input from the interface and process it, finally update the interface

• runApp(“Hello Shiny”) in R

5Zurich R User Group Meetups

December

Work-through Example

library(shiny)

shinyUI(fluidPage(

titlePanel("Hello Shiny!"), # define title

sidebarLayout( # choose layout

sidebarPanel(

sliderInput("bins", "Number of bins:", min = 1, max = 50,

value = 30)

),

mainPanel(

plotOutput("distPlot")

))

))

6Zurich R User Group Meetups

December

Work-through Example

x <- faithful[, 2] # Old Faithful Geyser data

bins <- seq(min(x), max(x), length.out = n + 1) # n is number of bins

hist(x, breaks = bins, col = 'darkgray', border = 'white')

7Zurich R User Group Meetups

December

Work-through Example

x <- faithful[, 2] # Old Faithful Geyser data

bins <- seq(min(x), max(x), length.out = n + 1) # n is number of bins

hist(x, breaks = bins, col = 'darkgray', border = 'white')

x <- faithful[, 2] # Old Faithful Geyser data

bins <- seq(min(x), max(x), length.out = input$bins + 1)

hist(x, breaks = bins, col = 'darkgray', border = 'white')

8Zurich R User Group Meetups

December

Work-through Example

x <- faithful[, 2] # Old Faithful Geyser data

bins <- seq(min(x), max(x), length.out = n + 1) # n is number of bins

hist(x, breaks = bins, col = 'darkgray', border = 'white')

library(shiny)

shinyServer(function(input, output) {

output$distPlot <- renderPlot({

x <- faithful[, 2] # Old Faithful Geyser data

bins <- seq(min(x), max(x), length.out = input$bins + 1)

hist(x, breaks = bins, col = 'darkgray', border = 'white')

})

})

9Zurich R User Group Meetups

December

Work-through Example

• runApp(“Hello Shiny”)

10Zurich R User Group Meetups

December

Deploy and Share

• Once the application is ready, it is free to share with the public

• Cost: free for 25 hours/month, up to 10,000 hours/month

• Wide range of applications on Shinyapp.io• https://jnuke2000.shinyapps.io/ShinyDash

• https://leehbi.shinyapps.io/Sales-Pricing-Tool/

• https://healthrank.shinyapps.io/demo/

11Zurich R User Group Meetups

December

More Resources

• Cheat sheets

• Tutorial

• Shiny gallery

12Zurich R User Group Meetups

December

Final Notes

• Demo website: http://t.uzh.ch/se

• My contact: craigwang247@gmail.com

• Thanks Christoph and Heidi for organizing this, also Sanitas for sponsoring the venue.

13Zurich R User Group Meetups

December

top related