180 likes | 248 Vues
s hiny in R. the fundamentals of getting started. What Is It?. New package in R to create web apps Web app built entirely in R, but can also incorporate HTML, CSS, and JavaScript for more flexibility By default, the UI is simple to create and view
E N D
shiny in R the fundamentals of getting started
What Is It? • New package in R to create web apps • Web app built entirely in R, but can also incorporate HTML, CSS, and JavaScript for more flexibility • By default, the UI is simple to create and view • Built-in widgets for displaying plots, tables, and any other printed output from R
Simple Example > runExample("01_hello")
ui.R & server.R • Two fundamental entities to any Shiny web app • ui.R • Designates the user interface of your app • server.R • Contains all the nuts and bolts of your app
The Flow Start ui.R input$tag output$tag server.R
ui.R in Detail • The three fundamental components of ui.R: • headerPanel() • sidebarPanel() • selectInput() • checkboxGroupInput() • mainPanel()
ui.R Syntax To be memorized!
The Flow Start ui.R input$tag output$tag server.R
server.R in Detail – input$tag • input$tag • Whatever options are selected under sidebarPanel() in ui.R is passed to the server.R script • input$dataset becomes either “Products”, “Clients”, or “All data” string, depending on which one the user chooses • input$dataset is reactionary, which means it always changes each time the user decides to select any new value • Beware!! The $ in input$tag here does not refer to any column in the input object tag
server.R in Detail – input$tag(continued) • What does input$dataset do? • Anything you want to do with it
The Flow Start ui.R input$tag output$tag input$dataset = “Products” OR input$dataset = “Clients” OR input$dataset = “All data” server.R
server.R in Detail – output$tag • ‘output’s themselves have tags! • The output is passed to ui.R and recognized under mainPanel() tag tag
server.R Syntax To be memorized!
Summary • User chooses the inputs • Inputs are stored in input$tags • input$tagsare manipulated in server.R • server.R returns output (tables, charts, printed text etc.) in the form of output$tags • The output$tagsfrom server.R is then accepted by ui.R and displayed on the dashboard for the user
Tips • Start small • Keep track of your parentheses • Work on ui.R first • Reference my cheatsheet • github.com/alaneng/personal • Frustration will be commonplace • https://groups.google.com/forum/?fromgroups#!forum/shiny-discuss Check out Glimmer -- host your web app online!
I’m for hire! • alanfaieng@gmail.com • linkedin.com/in/alanfaieng • github.com/alaneng/personal • @alanengdata