Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Introduction to Interactive Shiny Web
Applications
Olga Scrivner
University of Cincinnati
November 28, 2018
Objectives
Learn and practice R/Shiny basics
Explore Shiny templates and widgets
Create and deploy an interactive web application
Learn about Shiny apps for research and in teaching
https://languagevariationsuite.wordpress.com/
23
Today’s Workshop Material
082-word-cloud.zip
workshopshiny-final.zip
Today’s slides
Useful links
RStudio Basics
What is RStudio?
RStudio is an open source “set of integrated tools to help you
be more productive with R”
Shiny is a package from RStudio to build interactive web
interfaces/pages/applications
Two software packages:
Base-R
RStudio
26
Getting Started
RStudio is a graphical user interface interface for R.
http://www.rstudio.com/products/rstudio/download/
27
Getting Started
PC desktop - start button
RStudio Shortcut Icon
28
RStudio
RStudio Screen
RStudio
http://dss.princeton.edu/training/RStudio101.pdf
R scripts are just text files with the “.R” extension
30
Open New Files
Create a NEW FILE:
File > New File > R Script
31
RStudio Tour
32
Editor: “Source/Script”
33
Console: “Command Line”
34
History and Memory
35
Extremely Useful Panel
Shows a list of all the R libraries installed
Indicates whether the library is currently loaded
36
Packages: Libraries
Click to Activate and Deactivate a package
37
Packages
Select Session > Set Working Directory > Choose Directory >
Select your folder > Open
38
Telling R Where Your Files Are
39
Opening and Saving Files
Save your Untitled R script
Shiny Basics
Shiny Structure
http://littleactuary.github.io/blog/Web-application-framework-with-Shiny/ http://deanattali.com/blog/building-shiny-apps-tutorial/
41
Examples
Shiny Gallery - link
Show Me Shiny - link
Interactive Dashboard - link
https://languagevariationsuite.wordpress.com/
42
Installing Shiny Package
Bottom right window:
Packages
Select Install
43
Installing Shiny Package
44
Selecting Shiny Package
45
Run
Shiny Demo
Run Demo in R script
FIRST LINE of YOUR SCRIPT (top left panel)
TYPE:
runExample(“04_mpg”)
46
Run
Shiny Demo
Run Demo in R script
How to RUN your commands from the R script:
Keep your cursor at the FIRST LINE
Select RUNPlace cursor on the line or
select runExample(“04_mpg”)
47
Run
Shiny Demo
Run Demo in R script Demo in the Browser
Place cursor on the line or
select runExample(“04_mpg”)
48
Closing Demo App
Click STOP sign in your CONSOLE (bottom left). Your browser viewer will turn grey.
49
A Closer Look at the Shiny App
runExample("04_mpg")
Shiny script is called app.R
It activates TWO libraries (packages)
Use # (hashtag) to make comments
50
Can You Find Outlier(s)?
51
A Closer Look at the Shiny Interactivity
1. Scroll to the very END
52
2. Focus on this part
3. Deselect Show outliers
A Closer Look at the Shiny Interactivity
53
A Closer Look at the Shiny Interactivity
54
Change Variable
INPUT OUTPUT
Practice 1: Open Shiny App
Download and unzip 082-word-cloud.zip
Set Directory to 082-word-cloud folder
Find a file UI.R
Open UI.R (File > Open File > Open)
55
https://github.com/rstudio/shiny-examples/tree/master/082-word-cloud
Practice 1: Run Shiny App
56
Practice 1: Run Shiny App
57
UI.R - Layout
58
Practice 2: Identify Elements in UI.R
Strings - “green”
Numbers - blue
Functions, Variables - black
Comments - # green
HTML Tags
h1() = header1 , h2(), h3() ...
br() = line break
p() = paragraph
hr() = line
http://shiny.rstudio.com/articles/tag-glossary.html
HTML Tags
h1(“My Header”)
p(“My paragraph”)
http://shiny.rstudio.com/articles/tag-glossary.html
Strings - “green”
Change Title
Add subtitle h2()
Add line break br()
Add horizontal line hr()
Save File (File>Save)
RunApp
Practice 3: HTML Title Panel
Do NOT forget COMMAS
Practice 4: HTML Main Panel
Add paragraph p()
Comment out href
- # at the beginning of
the line
Save File (File>Save)
RunApp
Practice 4: HTML Main Panel
Do NOT forget COMMAS
Possible Errors - Syntax
Missing Commas
Creating a Shiny App
Create New Shiny App
Layout Functions and Data
Create New Shiny App
Sidebar Position
Layout Guide
https://shiny.rstudio.com/articles/layout-guide.html
Sidebar layout Tabset layout
Control Widgets
Widget is a web element for user interaction:
Basic Widgets
https://shiny.rstudio.com/tutorial/written-tutorial/lesson3/
Widgets
- Widget may have additional options, e.g. selected=, value=
- Widgets can be placed in sidebarPanel or mainPanel
Widget Content
- Each widget requires two arguments:
- a name of the widget (=id)
- a label (a text that appears in the app)
fileInput("file", "File input:")
name:
label:
file
File input
Unzip and Open workshopshiny-final
- RunApp
- Identify UI elements
- What are two widgets in your
App? Where are they?
Input and Output
IU.R SERVER.R
https://shiny.rstudio.com/reference/shiny/latest/
Connecting Widget and User: Execution
- When a user changes the widget, the value is also changed
credits: bit.ly/shiny-quickstart-1
Input and Output
IU.R SERVER.R
https://shiny.rstudio.com/reference/shiny/latest/
Reactive Input Data in SERVER.R
- This function will read
a csv file
- This function will
renders a table
- Input file will come
from UI.R when csv is
uploaded
Deployment
Deployment
Deploy with Shinyapps.io
My Shinyapps.io
My Shinyapps.io
Deployment on Jetstream
Pros:
You can have a persistent Shiny app available for no charge.
Can handle short-term high usage.
Help is available
Cons:
Need to request allocation from XSEDE.
Need to keep it running.
Will need to use Linux command line.
Research and Teaching
Customizable Online Tools:
Statistics, Visualization, Data Preprocessing
languagevariationsuite.cominteractivetextminingsuite.com
Thank you!
87
@obscrivn
obscrivn@indiana.edu
Presented by Olga Scrivner
Credits
• https://www.rstudio.com/wp-content/uploads/2014/07/RStudio-Logo-Blue-Gradient.png
• http://www.mcclellandlegge.com/img/shiny-logo.png
• http://deanattali.com/blog/building-shiny-apps-tutorial/
• http://littleactuary.github.io/blog/Web-application-framework-with-Shiny/
• https://shiny.rstudio.com/
• http://dss.princeton.edu/training/RStudio101.pdf

More Related Content

Introduction to Interactive Shiny Web Application