class: center, middle, inverse, title-slide # Lecture 10: Interactive web apps with Shiny ### Mikhail Dozmorov ### Virginia Commonwealth University ### 10-22-2020 --- ## What is Shiny? - Shiny is a framework for developing interactive, web-based tools with R, used for data exploration - Dynamic code execution, depending on user's input - It's maintained by RStudio, and there's robust documentation and video tutorials .small[ https://shiny.rstudio.com/gallery/ https://shiny.rstudio.com/tutorial/ https://shiny.rstudio.com/articles/ ] --- ## Parts of a Shiny App At minimum, a Shiny app has two components: - `ui.R` - User Interface, code to create front-end - `server.R` - Server code performing functions in backend It is possible to create a single file `app.R` containing code for both components ``` r library(shiny) ui <- fluidPage() server <- function(input, output) {} shinyApp(ui = ui, server = server) ``` .small[ https://shiny.rstudio.com/articles/app-formats.html ] --- ## Creating your first Shiny app 1. Create a new project in RStudio (either in a new directory or existing directory) 2. Select Shiny app and whether you want it to be a single file (preferred), or multiple files 3. Give a name to your app --- ## Running your first Shiny app - Save the code to the `app.R` file in the folder "My-first-app" ``` r library(shiny) runApp("My-first-app") ``` - Open `app.R` in RStudio and click the `Run App` button --- ## Intro to Shiny - [lecture4-shiny.pdf](../../slides/lecture4-shiny.pdf) by Katherine Wilson - [iris-app.R](../../slides/iris-app.R) --- ## How to start with Shiny [How to start with Shiny, Part 1](https://github.com/rstudio-education/shiny.rstudio.com-tutorial/blob/master/how-to-start-shiny-part-1.pdf) [How to start with Shiny, Part 2](https://dsba5122.com/files/shiny-reactivity.pdf) Slides by Garrett Grolemund