First things first: package installation…

# install.packages("shiny")             # Shiny
# install.packages("shinydashboard")    # Shiny dashboards
# install.packages("DT")                # Package for datatables (just in case)

… and activation + load the data. MAKE SURE THE songs.RData and movies.RData files are in the right place!

library(tidyverse)        # Just to be sure it's the first thing that is done...
library(shiny)
library(shinydashboard)
library(DT)

load("songs.RData")
load("movies.RData")

Songs dataset: exercises

The empty dashboard is given below:

ui <- dashboardPage(           # FULL PAGE
    dashboardHeader(),         # Header zone
    dashboardSidebar(),        # Sidebar zone
    dashboardBody()            # Body zone
)  

server <- function(input, output){  # Server: computations!
    
}

# Run the app ----
shinyApp(ui = ui, server = server)  # Aggregates the app.

0. Give a title to the dashboard. Something like “Songs Dashboard”.

1. GOAL: Create a widget to perform a filter on popularity and display the filtered data

  1. in the sidebar, create a slider that goes from 0 to 100. Call the input pop for simplicity. Execute to check! For documentation on slider, type “sliders shiny” in Google and/or have a look at https://shiny.rstudio.com/articles/sliders.html

  2. render the songs dataset as a DataTable in the server and load it in the body of the UI. Hint use a variable name like output$table in the server and use DataTable formats!

  3. This table is not linked with the slider in the sidebar! Next step: inside the server, create a reactive dataset in which a filter updates the range of the popularity of the songs displayed in the UI (Hint: use input$pop in the filter). Then render this dataset instead of the old one.

2. GOAL: add another widget and include a plot (on top of the current app).

  1. Create another widget on the energy variable that spans the unit interval [0,1].

  2. render a plot based on the reactive data with geom_point() with x = energy and y = popularity and color = speechiness

  3. add the filter on energy in the server! To see the effect, add a xlim(0,1) in the plot specs.

Movies dataset: exercises

Don’t forget to have loaded the movies dataset!

0. Give a title to the dashboard. Something like “Movies Dashboard”.

1. GOAL: Create a widget to perform a filter on duration and display the filtered data

  1. in the sidebar, create a slider that goes from 37 to 330. Call the input duration for simplicity.

  2. render the movies dataset as a DataTable in the server and load it in the body of the UI. Hint use a variable name like output$table in the server and use DataTable formats!

  3. Link the two sides with a reactive filter.

2. Create a checkboxGroupInput widget for the color of the movie (“Color” versus “Black and White”) and apply the corresponding filter in the server. If need be, see https://shiny.rstudio.com/reference/shiny/1.0.4/checkboxGroupInput.html

3. Add a plot which shows the average imdb_score (y-axis) of the films for each year (x-axis). Perform the analysis on the dynamic data (not on the original movies dataset).