It is a talk given by Vivian Zhang, CTO of SupStat Inc which is a leading Data Analytic consulting firm based in New York City, Shanghai and Beijing. NYC Open Data meetup are honored to host this event on Mar 24th,2014. You can find more information at www.meetup.com/nyc-open-data and www.nycopendata.com
4. Why build web application
R is great, and the Internet is great.
Everyone has a browser.
Communicate your results dynamically.
Create custom analytics tools to explore data.
·
·
·
·
4/30
5. Introduction to shiny
Open Sourced by RStudio November 2012
Not the first to get R in the browser (rApache, Rserve, Rook)
Default widgets and settings make it easy to generate apps
Don't need to know HTML, CSS and javascript to get started
Twitter Bootstrap for default UI - looks good
Web sockets for communication between client and server
Reactive Programming model
Works on Windows, Mac, Linux
·
·
·
·
·
·
·
·
5/30
6. Introduction to shiny
Ready to use shiny
Install R from CRAN
Useful to have Chrome, Firefox, Safari...
Rstudio or other texteditor
Install Shiny using R command: install.packages("shiny")
·
·
·
·
6/30
14. Reactive Programming
Similar to a spreadsheet. If you have a cell that is a function of another cell, e.g. "=A1*2", then any
time A1 is updated the cell that contains that function is automatically updated.
14/30
15. Reactive Programming
Similar to a spreadsheet. If you have a cell that is a function of another cell, e.g. "=A1*2", then any
time A1 is updated the cell that contains that function is automatically updated.
15/30
16. Reactive Programming
Similar to a spreadsheet. If you have a cell that is a function of another cell, e.g. "=A1*2", then any
time A1 is updated the cell that contains that function is automatically updated.
16/30
18. Functions for Input
sliderInput: Constructs a slider widget to select a numeric value from a range.
selectInput: Create a select list that can be used to choose a single or multiple items from a list
of values.
numericInput: Create an input control for entry of numeric values
checkboxInput: Create a checkbox that can be used to specify logical values.
radioButtons: Create a set of radio buttons used to select an item from a list.
textInput: Create an input control for entry of unstructured text values
·
runExample("01_hello")-
·
runExample("02_text")-
·
runExample("02_text")-
·
runExample("04_mpg")-
·
runExample("06_tabsets")-
·
runExample("02_text")-
18/30
19. Functions for Processing
reactive: Wraps a normal expression to create a reactive expression.
renderPlot: Renders a reactive plot that is suitable for assigning to an output slot.
renderPrint: Makes a reactive version of the given function that captures any printed output.
renderTable: Creates a reactive table that is suitable for assigning to an output slot
renderText: Makes a reactive version of the given function that also uses cat to turn its result
into a single element character vector.
·
runExample("02_text")-
·
runExample("01_hello")-
·
runExample("02_text")-
·
runExample("02_text")-
·
runExample("03_reactivity")-
19/30
20. Functions for Output
plotOutput: Render a renderPlot within an application page.
tableOutput: Render a renderTable within an application page.
verbatimTextOutput: Render a reactive output variable as verbatim text within an application
page.
textOutput: Render a reactive output variable as text within an application page.
·
runExample("01_hello")-
·
runExample("02_text")-
·
runExample("02_text")-
·
runExample("02_text")-
20/30
22. Tab Panels
Tabsets are created by calling the tabsetPanel function with a list of tabs created by the tabPanel
function. Each tab panel is provided a list of output elements which are rendered vertically within
the tab.
·
runExample("06_tabsets")-
22/30
23. UI Enhancements
We added a helpTextcontrol to provide additional clarifying text alongside our input controls.
We added a submitButtoncontrol to indicate that we don’t want a live connection between
inputs and outputs. This is especially useful if computing output is computationally expensive.
We added h4elements into the output pane. Shiny offers a variety of functions for including HTML
elements directly in pagesS.
·
·
·
runExample("07_widgets")-
23/30
24. Uploading Files
File upload controls are created by using the fileInputfunction in your ui.R file.
access the uploaded data similarly to other types of input: by referring to input$inputId.
The file contents can be accessed by reading the file named by the datapath column
·
·
·
runExample("09_upload")-
24/30
25. Dynamic UI
The conditionalPanelfunction, which is used in ui.R and wraps a set of UI elements that need
to be dynamically shown/hidden
The renderUIfunction, which is used in server.R in conjunction with the htmlOutput function in
ui.R, lets you generate calls to UI functions and make the results appear in a predetermined place
in the UI
·
·
runGist("https://gist.github.com/wch/4034323")-
25/30
27. Sharing Apps to Run Locally
Gist One easy way is to put your code on gist.github.com, a code pasteboard service from GitHub.
Both server.R and ui.R must be included in the same gist, and you must use their proper
filenames. See https://gist.github.com/3239667 for an example.
GitHub repository If your project is stored in a git repository on GitHub, then others can download
and run your app directly. An example repository is at https://github.com/rstudio/shiny_example.
·
·
27/30
28. Deploying Over the Web
Self-hosted Shiny Server With our Shiny Server software, you can deploy Shiny applications over
the web so that users need only a web browser and your application’s URL. You’ll need a Linux
server and Shiny Server.
RStudio-hosted Shiny Server Want to deploy over the web but prefer not to run your own server?
We’re currently beta testing a subscription-based hosting service for Shiny.
·
·
28/30