introduction r shiny
TRANSCRIPT
![Page 1: Introduction r Shiny](https://reader036.vdocument.in/reader036/viewer/2022082713/55cf9911550346d0339b5de3/html5/thumbnails/1.jpg)
A Quick Introduction to R ShinyAlec Stephenson 14 November 2013
COMPUTATIONAL INFORMATICS
![Page 2: Introduction r Shiny](https://reader036.vdocument.in/reader036/viewer/2022082713/55cf9911550346d0339b5de3/html5/thumbnails/2.jpg)
Presentation title | Presenter name2 |
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 Shinyby Chris Beeley
![Page 3: Introduction r Shiny](https://reader036.vdocument.in/reader036/viewer/2022082713/55cf9911550346d0339b5de3/html5/thumbnails/3.jpg)
Presentation title | Presenter name3 |
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
![Page 4: Introduction r Shiny](https://reader036.vdocument.in/reader036/viewer/2022082713/55cf9911550346d0339b5de3/html5/thumbnails/4.jpg)
Presentation title | Presenter name4 |
Hello Shiny
• ui.RshinyUI(pageWithSidebar((
headerPanel, sidebarPanel, mainPanel))
• server.RshinyServer(function(input, output) {……})
![Page 5: Introduction r Shiny](https://reader036.vdocument.in/reader036/viewer/2022082713/55cf9911550346d0339b5de3/html5/thumbnails/5.jpg)
Presentation title | Presenter name5 |
Hello Shiny: ui.R
•headerPanel("Hello Shiny!")• sidebarPanel(sliderInput("obs", "Number of
observations:", min = 1, max = 1000, value = 500) )•mainPanel(plotOutput("distPlot") )
![Page 6: Introduction r Shiny](https://reader036.vdocument.in/reader036/viewer/2022082713/55cf9911550346d0339b5de3/html5/thumbnails/6.jpg)
Presentation title | Presenter name6 |
Hello Shiny: server.R
output$distPlot <- renderPlot({dist <- rnorm(input$obs) hist(dist) })
![Page 7: Introduction r Shiny](https://reader036.vdocument.in/reader036/viewer/2022082713/55cf9911550346d0339b5de3/html5/thumbnails/7.jpg)
Presentation title | Presenter name7 |
Running Web Apps (Local Browser)
library(shiny)
runApp("folder_name")
runExample()runExamples("01_hello")runExamples("07_widgets")
![Page 8: Introduction r Shiny](https://reader036.vdocument.in/reader036/viewer/2022082713/55cf9911550346d0339b5de3/html5/thumbnails/8.jpg)
Presentation title | Presenter name8 |
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"))
![Page 9: Introduction r Shiny](https://reader036.vdocument.in/reader036/viewer/2022082713/55cf9911550346d0339b5de3/html5/thumbnails/9.jpg)
Presentation title | Presenter name9 |
Widgets: ui.R
•mainPanel(h4("Summary"),
verbatimTextOutput("summary"), h4("Observations"),
tableOutput("view") )
![Page 10: Introduction r Shiny](https://reader036.vdocument.in/reader036/viewer/2022082713/55cf9911550346d0339b5de3/html5/thumbnails/10.jpg)
Presentation title | Presenter name10 |
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) })
![Page 11: Introduction r Shiny](https://reader036.vdocument.in/reader036/viewer/2022082713/55cf9911550346d0339b5de3/html5/thumbnails/11.jpg)
Presentation title | Presenter name11 |
Tabsets: ui.R
•headerPanel("Tabsets")• sidebarPanel(
radioButtons("dist", "Distribution type:", list("Normal"="norm", "Uniform" ="unif", "Log-normal" = "lnorm", "Exponential" = "exp")), br(), sliderInput("n", "Number of observations:", value = 500, min = 1, max = 1000) )
![Page 12: Introduction r Shiny](https://reader036.vdocument.in/reader036/viewer/2022082713/55cf9911550346d0339b5de3/html5/thumbnails/12.jpg)
Presentation title | Presenter name12 |
Tabsets: ui.R
•mainPanel( tabsetPanel( tabPanel("Plot", plotOutput("plot")),tabPanel("Summary", verbatimTextOutput("summary")), tabPanel("Table", tableOutput("table")) ))
![Page 13: Introduction r Shiny](https://reader036.vdocument.in/reader036/viewer/2022082713/55cf9911550346d0339b5de3/html5/thumbnails/13.jpg)
Presentation title | Presenter name13 |
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()) })
![Page 14: Introduction r Shiny](https://reader036.vdocument.in/reader036/viewer/2022082713/55cf9911550346d0339b5de3/html5/thumbnails/14.jpg)
Presentation title | Presenter name14 |
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/
![Page 15: Introduction r Shiny](https://reader036.vdocument.in/reader036/viewer/2022082713/55cf9911550346d0339b5de3/html5/thumbnails/15.jpg)
COMPUTATIONAL INFORMATICS
Thank youComputational InformaticsAlec Stephenson
t +61 3 9545 8019e [email protected]