A Quick Introduction to R Shiny Alec Stephenson
- Slides: 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 shiny. UI(page. With. Sidebar(( header. Panel, sidebar. Panel, main. Panel)) • server. R shiny. Server(function(input, output) {……}) 4 | Presentation title | Presenter name
Hello Shiny: ui. R • header. Panel("Hello Shiny!") • sidebar. Panel(slider. Input("obs", "Number of observations: ", min = 1, max = 1000, value = 500) ) • main. Panel(plot. Output("dist. Plot") ) 5 | Presentation title | Presenter name
Hello Shiny: server. R output$dist. Plot <- render. Plot({ dist <- rnorm(input$obs) hist(dist) }) 6 | Presentation title | Presenter name
Running Web Apps (Local Browser) library(shiny) run. App("folder_name") run. Example() run. Examples("01_hello") run. Examples("07_widgets") 7 | Presentation title | Presenter name
Widgets: ui. R • header. Panel("More Widgets") • sidebar. Panel( select. Input("dataset", "Choose a dataset: ", choices = c("rock", "pressure", "cars")), numeric. Input("obs", "Number of observations to view: ", 10), help. Text("Blah Blah"), submit. Button("Update View")) 8 | Presentation title | Presenter name
Widgets: ui. R • main. Panel( h 4("Summary"), verbatim. Text. Output("summary"), h 4("Observations"), table. Output("view") ) 9 | Presentation title | Presenter name
Widgets: server. R dataset. Input <- reactive({ switch(input$dataset, "rock" = rock, "pressure" = pressure, "cars" = cars) }) output$summary <- render. Print({ dataset <- dataset. Input() summary(dataset) }) output$view <- render. Table({ head(dataset. Input(), n = input$obs) }) 10 | Presentation title | Presenter name
Tabsets: ui. R • header. Panel("Tabsets") • sidebar. Panel( radio. Buttons("dist", "Distribution type: ", list("Normal"="norm", "Uniform" ="unif", "Lognormal" = "lnorm", "Exponential" = "exp")), br(), slider. Input("n", "Number of observations: ", value = 500, min = 1, max = 1000) ) 11 | Presentation title | Presenter name
Tabsets: ui. R • main. Panel( tabset. Panel( tab. Panel("Plot", plot. Output("plot")), tab. Panel("Summary", verbatim. Text. Output("summary")), tab. Panel("Table", table. Output("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 <- render. Plot({ dist <- input$dist; n <input$n; hist(data(), main=paste 0('r', dist, '(', n, ')')) }) output$summary <- render. Print({ summary(data()) }) output$table <- render. Table({ 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 alec. stephenson@csiro. au COMPUTATIONAL INFORMATICS
- Alec stephenson
- Quick find algorithm
- Collision forces quick check
- Hypothesis of ariens and stephenson
- Definisi profesi humas menurut howard stephenson
- Brief history of scouting
- Cheri stephenson
- Brenda stephenson
- Ginger carney
- Tiffany stephenson
- George stephenson
- Kurt stephenson
- Bear
- Which line creates a feeling of height and formality?
- Formation r shiny
- I look like a nail but a bud am i