Class 23 Applications in R Shiny Hydroinformatics Fall

  • Slides: 13
Download presentation
Class 23: Applications in R (Shiny) Hydroinformatics – Fall 2017

Class 23: Applications in R (Shiny) Hydroinformatics – Fall 2017

Learning Objectives • Create interactive web-based applications for data visualization and publishing using R

Learning Objectives • Create interactive web-based applications for data visualization and publishing using R and Shiny

Pre-class • Created an account on shinyapps. io • Steps 1 and 2 (install

Pre-class • Created an account on shinyapps. io • Steps 1 and 2 (install rsconnect and authorize your account)

Shiny is an open source R package that provides an elegant and powerful web

Shiny is an open source R package that provides an elegant and powerful web framework for building web applications using R. Shiny helps you turn your analyses into interactive web applications without requiring HTML, CSS, or Java. Script knowledge. Install the “shiny” package in R. (Tools>Install Packages)

Example R Shiny Apps Gallery of Examples: • https: //www. rstudio. com/products/shiny-user-showcase/ USGS Fisheries

Example R Shiny Apps Gallery of Examples: • https: //www. rstudio. com/products/shiny-user-showcase/ USGS Fisheries App: • https: //gallery. shinyapps. io/lake_erie_fisheries_stock_assessment_app / Data converter interface: • https: //gallery. shinyapps. io/rioweb/ Football Prediction App • https: //gallery. shinyapps. io/Predict. Aggie. Score. Results/

Create your own App Dynamic visualization of Old Faithful Eruption Times and Visitor Counts

Create your own App Dynamic visualization of Old Faithful Eruption Times and Visitor Counts • Create a new project in Rstudio • New Project>New Directory>Shiny Web Application • Give it a unique name • This will generate folders with the necessary structure

Structure of a Shiny App • Basic structure is either: • app. R (with

Structure of a Shiny App • Basic structure is either: • app. R (with ui and server components) or • ui. R and server. R • Run App button • • Run in window Run in viewer pane Run external (in browser window) Note: the “Run App” option is only available when you have the app. R, ui. R, or server. R script active

Structure of a Shiny App • ui. R • server. R • Form/architecture of

Structure of a Shiny App • ui. R • server. R • Form/architecture of the interface • (title. Panel, sidebar. Panel, etc. ) • User inputs • (slider. Input) • Displays/outputs • Functions for analysis • Plotting the histogram • Reading in/formatting data • (the example reads in data from the “faithful” dataset – an included dataset of Old Faithful geyser data)

Demo 1: Use static data files and add a plot to the output •

Demo 1: Use static data files and add a plot to the output • Store and use static data files • Within application/project directory, create “data” folder • Save “Yellowstone. Visitor. Data. csv” in this data folder • Within the server function/script • Load visitor data in the app • Format so that Months are factors • Create a simple plot of visitor data (don’t forget to load ggplot 2!) • In ui function/script • Add a plot. Output • Run app

Demo 2: Get user input to dynamically update output • Many types of user

Demo 2: Get user input to dynamically update output • Many types of user inputs are available Example: Numeric input Add numeric. Input to ui section Add an output display Add function (which uses the numeric input) to the server section • Note how the input/outputs are linked • Save and Run app • •

Publish to Shinyapps. io • Click on the publish icon • When finished, the

Publish to Shinyapps. io • Click on the publish icon • When finished, the app will open in a browser window • View your app status (usage, url, settings) on shinyapps. io dashboard

Challenge: Create your own App! In teams/partners, create an application under one of the

Challenge: Create your own App! In teams/partners, create an application under one of the following themes: • Water quality • Climate Projection data • …something original! For Assignment 8, you will create an interactive application that uses one or more data sources to effectively communicate information. Be prepared to share your app with the class in Class 25!

For help: • Double check your capitalization, spelling, commas, etc. • Use Google and

For help: • Double check your capitalization, spelling, commas, etc. • Use Google and Stack Overflow! • https: //codeshare. io/2 K 6 Eg. E (copy and paste your code and I will try to help real-time) • Email me your code at carly. hansen@utah. edu