Introduction R Shiny
Introduction R Shiny
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
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
Hello Shiny
ui.R
Hello Shiny: ui.R headerPanel("Hello Shiny!") sidebarPanel(sliderInput("obs", "Number of observations:", min = 1, max = 1000, value = 500) ) mainPanel(plotOutput("distPlot") )
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: 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) })
Tabsets: ui.R mainPanel( tabsetPanel( tabPanel("Plot", plotOutput("plot")), tabPanel("Summary", verbatimTextOutput("summary")), tabPanel("Table", tableOutput("table")) ))
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()) })
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/
Thank you
Computational Informatics Alec Stephenson
COMPUTATIONAL INFORMATICS