5.12. Example Jupyter R notebook#

Jupyter is a web application that presents notebooks (like this).

5.12.1. Example cell#

The notebook is divided into “cells” that can be tagged for Markdown or Code (dropdown above).

  • Double-click to edit a cell.

  • Shift-enter to evaluate the cell.

  • Jupyter sends the contents of the cell back to a “Kernel” running on the server to evaluate.

  • If there is output, it’s displayed below the cell.

5.12.2. You can preload data and libraries#

For example, there are preloaded datasets in jacobs2016data:

  • class.data

  • feedback.topics

  • lecturer.scores

  • module.scores

  • student.demographics

# working dir for data
setwd("jacobs2016data")
getwd()

‘/media/home_nfs_import/home_iagpu/pers/marc.buffat/JupyterAI/jacobs2016data’

# Load the data
#library(jacobs2016data)
data(class.data)
data(student.demographics)
data(lecturer.scores)
data(module.scores)
data(feedback.topics)

5.12.3. This is just like Rserve, but with a GUI#

So you send a command and get back standard out

class.data
A data.frame: 5 × 4
yearstudentsgtasmean.marks
<int><dbl><dbl><dbl>
2010 35 40.505
2011 89 70.689
2012162 90.603
2013 85180.745
2014 87140.680
options(repr.plot.width=7, repr.plot.height=3.2)  # fit in browser display
par(mfrow=c(1,2))
boxplot(score~year, data=lecturer.scores, col="maroon", main="Lecturer scores")
boxplot(score~year, data=module.scores, col="maroon", main="Module scores")
par(mfrow=c(1,1))

png

5.12.5. Students can immediately alter functions and try things on their own#

So you can present them with functions and let them modify them … and realistically alternate Theory → Worked example → Hands-on in class. (Or in a tutorial / demo at a conference).

options(repr.plot.width=4.2, repr.plot.height=3.8)
class_year = 2010

show.feedback <- function(year, highlight, methodology) {
    df = feedback.topics[feedback.topics$year == year,]
    pie(df$fraction.of.feedback,
        labels=sprintf('%s\n%d%%', df$topic, round(df$fraction.of.feedback*100)),
        clockwise=T,
        col=ifelse(df$topic %in% highlight, 'maroon', 'lightgray'),
        main=sprintf('%d - %s',year, methodology))
}
show.feedback(2010, c('Pace'), 'Traditional lecture style')
#show.feedback(2011, c('Pace', 'Support'), '3 extra hours of lab')
#show.feedback(2012, c('Lecturer', 'Material'), 'YouTube videos + in-class work')
#show.feedback(2013, c('Lecturer', 'Support'), 'Written lecture notes + in-class work')
#show.feedback(2014, c('Support'), '10-min. lectures + sticky notes + in-class work')

png

5.13. Aside notes#

By the way, yes Jupyter can present LaTeX markup (between $$ symbols – using the MathJax javascript library):

\[log(Q) = \alpha - \eta log(P)\]

5.13.1. References#