Interactive Data Visualizations



Data Science in a Box

datasciencebox.org

Cornell College
DSC 223 - Fall 2022

October 17th, 2022

Shiny

  • Shiny is an R package that makes it easy to build interactive web apps straight from R
  • You can host standalone apps on a webpage or embed them in R Markdown documents or build dashboards
  • You can also extend your Shiny apps with CSS themes, htmlwidgets, and JavaScript actions
  • Learn more at shiny.rstudio.com

High level view

  • Every Shiny app has a webpage that the user visits, and behind this webpage there is a computer that serves this webpage by running R

  • When running your app locally, the computer serving your app is your computer

  • When your app is deployed, the computer serving your app is a web server

minecr.shinyapps.io/fm-speeches-covid19-simple

ggiraph

ggiraph is a tool that allows you to create dynamic ggplot graphs. This allows you to add tooltips, hover effects and JavaScript actions to the graphics. The package also allows the selection of graphical elements when used in shiny applications.

Interactivity is added to ggplot geometries, legends and theme elements, via the following aesthetics:

Why use ggiraph

  • You want to provide your readers with more information than the basic information available; you can display a tooltip when the user’s mouse is on a graphical element, you can also visually animate elements with the same attribute when the mouse passes over a graphical element, and finally you can link a JavaScript action to the click, such as opening a hypertext link.
  • You want to allow users of a Shiny application to select graphical elements; for example, you can make the points of a scatter plot selectable and available as a reactive value from the server part of your application. With Shiny, ggiraph allows interaction with graph elements, legends elements, titles and ggplot theme elements from the server part; each selection is available as a reactive value.

Data: Book weight and volume

The allbacks data frame gives measurements on the volume and weight of 15 books, some of which are paperback and some of which are hardback

  • Volume - cubic centimetres
  • Area - square centimetres
  • Weight - grams
# A tibble: 15 × 4
   volume  area weight cover
    <dbl> <dbl>  <dbl> <fct>
 1    885   382    800 hb   
 2   1016   468    950 hb   
 3   1125   387   1050 hb   
 4    239   371    350 hb   
 5    701   371    750 hb   
 6    641   367    600 hb   
 7   1228   396   1075 hb   
 8    412     0    250 pb   
 9    953     0    700 pb   
10    929     0    650 pb   
11   1492     0    975 pb   
12    419     0    350 pb   
13   1010     0    950 pb   
14    595     0    425 pb   
15   1034     0    725 pb   

Weight vs Volume

Weight vs Volume Interactive-ggiraph

library(ggiraph)
books_girafe <- ggplot(allbacks, aes(x = volume, y = weight,
                tooltip=paste0("(",volume,",",weight,")"))) +
  
  geom_point_interactive(alpha = 0.7, size = 3)
girafe(ggobj = books_girafe,width_svg = 12)

Plotly

https://plotly.com/graphing-libraries/

https://plotly-r.com/overview.html

Weight vs Volume Interactive-plotly

library(plotly)
books_plotly <- plot_ly(allbacks, x= ~volume, y= ~weight,height = 450)
books_plotly