This lab gently introduces how to create an interactive dashboard in R.
You can create a new R Markdown file, or download the LAB-03 RMD templates:
Lab 04 builds on the static graphic created in Lab 03 by rendering key graphical elements, such as the trendline and legend, as interactive and responsive to user inputs, just like any other app. Visit the final app by clicking here.
The Lab 03 Gapminder visualization as an interactive app.
Recall that Shiny allows you to build interactive data products. An app’s interactivity occurs between user input and machine output.
ui.r
): Where end users exercise control
and view server outputsserver.r
): Where function operations occur
based on user inputsNote that in the server code, any dynamic code must be within a
“reactive context”, which typically lies within curly brackets, or
{ ... }
.
In addition to modifying your dashboard with your name, Lab 04 requires the following:
selectInput()
control function to the app UI and
connect it to the serverIn addition, you must install and load the following packages in your script.
library(shiny)
library(tidyverse)
library(flexdashboard)
library(shinydashboard)
Regardless of what visualization or Shiny packages you use, you must
place your Lab 03 visualization code within a renderPlot()
function.
Depending on which visualization package you choose, you will need to append a new trend line differently.
ggplot2
, consider using geom_line()
or
geom_path()
graphics
, consider using points()
or
lines()
Note that the trend line will contain the “reactive” shiny input. You only need to experiment with this part of the visualization code to be successful.
Regardless of your visualization or dashboard packages used, you must
use base Shiny function selectInput()
and list all possible
regions as well as a default selection.
Recall that the inputId =
argument accepts a character
string that becomes a unique identifier. When this ID is used in
conjunction with input$
, i.e. input$id
, it
acts as an object representing whatever value is chosen in
selectInput()
.
For example, if you choose “Europe East” in the UI with
selectInput(inputId = "my_example")
, then the server’s
input$my_example
now represents and acts as the value
“Europe East”.
Templates are provided to complete your dashboard using any of the following packages:
shiny
in “Lab-04-LastName-shiny-v3.R”flexdashboard
in “Lab-04-LastName-flex-v3.R”shinydashboard
in “Lab-04-LastName-sdbp-v3.R”Note that you need only use one, though all options will require
shiny
.
Function selectInput()
should be placed within
sidebarPanel()
.
The location of selectInput()
is provided.
Function selectInput()
should be placed within
sidebarMenu()
.
You need only submit your .Rmd
file for this week.
Remember to ensure the following before submitting your assignment.
See Google’s R Style Guide for examples of common conventions.