0% found this document useful (0 votes)
327 views

Introduction R Shiny

This document introduces R Shiny, which allows users to build interactive web applications directly from R without using HTML, JavaScript, or web programming. It provides examples of basic Shiny apps, including random number generation histograms and widget controls like sliders and dropdowns. More advanced features like tabsets with multiple panels are also demonstrated. The document encourages readers to create their own Shiny apps with their data and deploy them to web servers.

Uploaded by

Sacha Paricide
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
327 views

Introduction R Shiny

This document introduces R Shiny, which allows users to build interactive web applications directly from R without using HTML, JavaScript, or web programming. It provides examples of basic Shiny apps, including random number generation histograms and widget controls like sliders and dropdowns. More advanced features like tabsets with multiple panels are also demonstrated. The document encourages readers to create their own Shiny apps with their data and deploy them to web servers.

Uploaded by

Sacha Paricide
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

A Quick Introduction to R Shiny

Alec Stephenson 14 November 2013


COMPUTATIONAL INFORMATICS

Introduction
Write Simple Web Applications Using (Only) R No Need for HTML or Javascript Great for Communication and Visualization http://www.rstudio.com/shiny/showcase/ http://rstudio.github.io/shiny/tutorial/ Web Application Development Using R With Shiny by Chris Beeley

2 | Presentation title | Presenter name

Examples Outline
Showcase Examples
Modelling Heights & Weights of Schoolchildren Exploring Diamonds

Tutorial Examples
Hello Shiny: Random Samples Histogram Widgets: Data Tables & Summaries Tabsets: More Random Samples

My Own Examples
Co-authorship Network Fire Danger Maps

3 | Presentation title | Presenter name

Hello Shiny
ui.R

shinyUI(pageWithSidebar(( headerPanel, sidebarPanel, mainPanel))


server.R shinyServer(function(input, output) {})

4 | Presentation title | Presenter name

Hello Shiny: ui.R headerPanel("Hello Shiny!") sidebarPanel(sliderInput("obs", "Number of observations:", min = 1, max = 1000, value = 500) ) mainPanel(plotOutput("distPlot") )

5 | Presentation title | Presenter name

Hello Shiny: server.R


output$distPlot <- renderPlot({ dist <- rnorm(input$obs) hist(dist) })

6 | Presentation title | Presenter name

Running Web Apps (Local Browser)


library(shiny)
runApp("folder_name") runExample() runExamples("01_hello") runExamples("07_widgets")

7 | Presentation title | Presenter name

Widgets: ui.R headerPanel("More Widgets") sidebarPanel( selectInput("dataset", "Choose a dataset:", choices = c("rock", "pressure", "cars")), numericInput("obs", "Number of observations to view:", 10), helpText("Blah Blah Blah Blah"), submitButton("Update View"))
8 | Presentation title | Presenter name

Widgets: ui.R mainPanel( h4("Summary"), verbatimTextOutput("summary"), h4("Observations"), tableOutput("view") )

9 | Presentation title | Presenter name

Widgets: server.R
datasetInput <- reactive({ switch(input$dataset, "rock" = rock, "pressure" = pressure, "cars" = cars) }) output$summary <- renderPrint({ dataset <- datasetInput() summary(dataset) }) output$view <- renderTable({ head(datasetInput(), n = input$obs) })

10 | Presentation title | Presenter name

Tabsets: ui.R headerPanel("Tabsets") sidebarPanel(


radioButtons("dist", "Distribution type:", list("Normal"="norm", "Uniform" ="unif", "Lognormal" = "lnorm", "Exponential" = "exp")), br(), sliderInput("n", "Number of observations:", value = 500, min = 1, max = 1000) )

11 | Presentation title | Presenter name

Tabsets: ui.R mainPanel( tabsetPanel( tabPanel("Plot", plotOutput("plot")), tabPanel("Summary", verbatimTextOutput("summary")), tabPanel("Table", tableOutput("table")) ))

12 | Presentation title | Presenter name

Tabsets: server.R
data <- reactive({ dist <- switch(input$dist, norm = rnorm, unif = runif, lnorm = rlnorm, exp = rexp, rnorm); dist(input$n) })
output$plot <- renderPlot({ dist <- input$dist; n <input$n; hist(data(), main=paste0('r', dist, '(', n, ')')) }) output$summary <- renderPrint({ summary(data()) }) output$table <- renderTable({ data.frame(x=data()) })

13 | Presentation title | Presenter name

Conclusion
Have a go with your own data Put your application on a web server Send everyone the links: http://spark.rstudio.com/alec/fire/ http://spark.rstudio.com/alec/snet/

14 | Presentation title | Presenter name

Thank you
Computational Informatics Alec Stephenson

t +61 3 9545 8019 e [email protected]

COMPUTATIONAL INFORMATICS

You might also like