├── .DS_Store ├── .gitignore ├── 00_Introduction.ipynb ├── 01_Introduction, History and Perspectives.ipynb ├── 02_Jupyter notebooks - the inner workings.ipynb ├── 03_Image Analysis with k-Means Clustering.ipynb ├── 04_Reproducible research.ipynb ├── 05_Expanded Image Analysis Lab.ipynb ├── 06_Jupyter notebooks on Azure.ipynb ├── 07_Teaching with notebooks.ipynb ├── 08_Wrapup.ipynb ├── INSTALLATIONS.md ├── INSTALLATION_ADVANCED.md ├── LICENSE ├── README.md ├── _config.yml ├── aml_invite_users.png ├── data └── 03_Image_Analysis_with_k-Means │ └── r-package-downloads-2015-jan-may.csv ├── images ├── .DS_Store ├── 00_Welcome │ ├── login.png │ └── simulate-pi.png ├── 02_Jupyter_the_inner_workings │ ├── Notebook_sample_breast_cancer.png │ ├── azure-notebooks.png │ ├── jupyter architecture 1.png │ ├── jupyter architecture 2.png │ ├── jupyter hub logo.png │ ├── jupyter hub.png │ └── zeromq.png ├── 03_Image_Analysis_with_k-Means │ ├── densitypolygon-1.png │ ├── rpy2.png │ ├── segmented_bird.png │ ├── segmented_bird2.png │ ├── top-20-r-packages-machine-learning-downloads.jpg │ └── zebrafish_brain_10x.jpeg ├── 05_Expanded_Image_Analysis_Lab │ ├── a_query.jpg │ ├── hummingbird_mharris.jpg │ ├── segmented_bird.png │ ├── segmented_bird2.png │ └── whidbey_mharris.jpg └── 06_Notebooks_on_Azure │ ├── AzureML.png │ ├── Azure_conceptual_view.png │ ├── Azure_datacenters.png │ ├── Azure_services.jpg │ ├── Azure_services.png │ ├── CIS.png │ └── aml_invite_users.png └── notebook_basics ├── 01.Installing stuff.ipynb ├── 02.General anatomy.ipynb ├── 03.Interacting with filesystem.ipynb ├── 04.Interactive plotting.ipynb ├── 05.Changing R plot options in Jupyter.ipynb ├── 06.Creating a Jupyter slide show.ipynb ├── 07.Simple example - simulate pi.ipynb ├── imgs-reveal ├── overview.png └── shortcuts.png └── imgs ├── B01727_03.png └── nb_diagram.png /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .ipynb_checkpoints -------------------------------------------------------------------------------- /00_Introduction.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "slideshow": { 7 | "slide_type": "slide" 8 | } 9 | }, 10 | "source": [ 11 | "# Jupyter Notebooks for Reproducible Research\n", 12 | "\n", 13 | "\n", 14 | "\n", 15 | "\n", 16 | "\n", 17 | "* Material at: https://github.com/michhar/useR2016-tutorial-jupyter\n", 18 | "* Live session at: https://aka.ms/user-jupyter\n" 19 | ] 20 | }, 21 | { 22 | "cell_type": "markdown", 23 | "metadata": { 24 | "slideshow": { 25 | "slide_type": "slide" 26 | } 27 | }, 28 | "source": [ 29 | "# Housekeeping\n", 30 | "\n", 31 | "1. Ask questions at any time\n", 32 | "2. Use the sticky note for:\n", 33 | " - Red: I want help\n", 34 | " - Blue: All is good" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": { 40 | "slideshow": { 41 | "slide_type": "slide" 42 | } 43 | }, 44 | "source": [ 45 | "# Quick Poll" 46 | ] 47 | }, 48 | { 49 | "cell_type": "markdown", 50 | "metadata": { 51 | "slideshow": { 52 | "slide_type": "fragment" 53 | } 54 | }, 55 | "source": [ 56 | "* Have you used Jupyter notebooks before?" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": { 62 | "slideshow": { 63 | "slide_type": "fragment" 64 | } 65 | }, 66 | "source": [ 67 | "* Are you familiar with markdown syntax?" 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": { 73 | "slideshow": { 74 | "slide_type": "slide" 75 | } 76 | }, 77 | "source": [ 78 | "# What is a Jupyter notebook?\n", 79 | "\n", 80 | "* Interactive environment for running code\n", 81 | "* A way to mix text (markdown) and code\n", 82 | "* A way to create reports\n", 83 | "* A way to share samples and code snippets\n", 84 | "* A dynamic way of teaching" 85 | ] 86 | }, 87 | { 88 | "cell_type": "markdown", 89 | "metadata": { 90 | "slideshow": { 91 | "slide_type": "slide" 92 | } 93 | }, 94 | "source": [ 95 | "# Quick demo\n", 96 | "\n", 97 | "" 98 | ] 99 | }, 100 | { 101 | "cell_type": "markdown", 102 | "metadata": { 103 | "slideshow": { 104 | "slide_type": "slide" 105 | } 106 | }, 107 | "source": [ 108 | "# In today's session\n", 109 | "\n", 110 | "Item|Topic|Start time|Duration\n", 111 | "----|-----|---------|--------\n", 112 | " |Welcome|13:00|10\n", 113 | "1|History and perspective|13:10|10\n", 114 | "2|How does Jupyter work?|13:20|10\n", 115 | "3|Working with notebooks, using image example|13:30|30\n", 116 | "4|Notebooks and reproducible research|14:00|15\n", 117 | " |---- BREAK ---|14:15|15\n", 118 | "5|Lab - image analysis|14:30|45\n", 119 | "6|Jupyter Notebooks in the Azure Cloud|15:15|15\n", 120 | "7|Teaching concepts with notebooks|15:30|15\n", 121 | "8|Wrap up|15:45|15\n", 122 | " |--- Session ends ---|16:00| \n", 123 | "\n", 124 | "\n" 125 | ] 126 | }, 127 | { 128 | "cell_type": "markdown", 129 | "metadata": { 130 | "slideshow": { 131 | "slide_type": "slide" 132 | } 133 | }, 134 | "source": [ 135 | "# Log in to your notebook environment\n", 136 | "\n", 137 | "You should have:\n", 138 | "\n", 139 | "* URL\n", 140 | " - https://aka.ms/user-jupyter\n", 141 | "* User ID\n", 142 | "* Password\n", 143 | "\n", 144 | "In a browser (preferably chrome), navigate to the URL.\n", 145 | "\n", 146 | "Log in using your ID and password\n" 147 | ] 148 | }, 149 | { 150 | "cell_type": "markdown", 151 | "metadata": { 152 | "slideshow": { 153 | "slide_type": "slide" 154 | } 155 | }, 156 | "source": [ 157 | "# Logging in\n", 158 | "\n", 159 | "" 160 | ] 161 | }, 162 | { 163 | "cell_type": "markdown", 164 | "metadata": { 165 | "slideshow": { 166 | "slide_type": "slide" 167 | } 168 | }, 169 | "source": [ 170 | "# Success?\n", 171 | "\n", 172 | "Can you log in to the environment?\n", 173 | "\n", 174 | "* Use a blue sticky to indicate **yes**\n", 175 | "* Use a red sticky to indicate **no**\n", 176 | "\n" 177 | ] 178 | }, 179 | { 180 | "cell_type": "markdown", 181 | "metadata": { 182 | "slideshow": { 183 | "slide_type": "slide" 184 | } 185 | }, 186 | "source": [ 187 | "# Let's gets started!" 188 | ] 189 | } 190 | ], 191 | "metadata": { 192 | "celltoolbar": "Slideshow", 193 | "kernelspec": { 194 | "display_name": "R", 195 | "language": "R", 196 | "name": "ir" 197 | }, 198 | "language_info": { 199 | "codemirror_mode": "r", 200 | "file_extension": ".r", 201 | "mimetype": "text/x-r-source", 202 | "name": "R", 203 | "pygments_lexer": "r", 204 | "version": "3.2.2" 205 | } 206 | }, 207 | "nbformat": 4, 208 | "nbformat_minor": 0 209 | } 210 | -------------------------------------------------------------------------------- /01_Introduction, History and Perspectives.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "slideshow": { 7 | "slide_type": "slide" 8 | } 9 | }, 10 | "source": [ 11 | "# Introduction" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "metadata": { 17 | "slideshow": { 18 | "slide_type": "slide" 19 | } 20 | }, 21 | "source": [ 22 | "## What's so special about Jupyter notebooks?\n", 23 | "\n", 24 | "* Jupyter's power is in having code, data, and text all accessible from **one file viewed in a browser**, living locally or in the cloud. \n", 25 | "* The Jupyter Project used to be part of the IPython Project and has spun off. \n", 26 | "* It supports over 40 different languages (see this [article](https://github.com/ipython/ipython/wiki/IPython-kernels-for-other-languages)) and that is actively growing." 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": { 32 | "slideshow": { 33 | "slide_type": "slide" 34 | } 35 | }, 36 | "source": [ 37 | "## Text bits\n", 38 | "\n", 39 | "The text in a notebook is written in the simple __markdown__ language, making it a rich format capable of \"rendering\" latex, links, images and even html (since we're in a browser and the R kernel let's us). \n", 40 | "\n", 41 | "*However*, the **philosophy** of markdown is, above all else, to **make it readable** in either its rendered or plain text format. " 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": { 47 | "slideshow": { 48 | "slide_type": "slide" 49 | } 50 | }, 51 | "source": [ 52 | "## The \"new\" wave on the block (at least R-flavored notebooks)\n", 53 | "\n", 54 | "Amazing fact: in 2014, there were 80,000 jupyter notebooks on github. In 2015 the number almost tripled to 230,000. This shows how popular and fast-growing the usage is in the community. \n", 55 | "\n", 56 | "- github numbers from article by Alex Perrier [here](https://www.opendatascience.com/blog/jupyter-zeppelin-beaker-the-rise-of-the-notebooks/)" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": { 62 | "slideshow": { 63 | "slide_type": "notes" 64 | } 65 | }, 66 | "source": [ 67 | "More specific stats on the percentages of those notebooks which are using R may not be a representative dataset to glean a trend from at this point given the project is still very young." 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": { 73 | "slideshow": { 74 | "slide_type": "slide" 75 | } 76 | }, 77 | "source": [ 78 | "# History" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": { 84 | "ExecuteTime": { 85 | "end_time": "2016-06-26T12:14:23.041527", 86 | "start_time": "2016-06-26T19:14:22.949Z" 87 | }, 88 | "slideshow": { 89 | "slide_type": "slide" 90 | } 91 | }, 92 | "source": [ 93 | "\n", 94 | "\n", 95 | "## What I learned after reading the [IPython introductory paper](https://web.archive.org/web/20100602042637/http:/fperez.org/papers/ipython07_pe-gr_cise.pdf) by Fernando Perez\n", 96 | "\n", 97 | "Originating in 2001, it was created initially by Perez as an enhanced interactive python shell. \n", 98 | " \n", 99 | "IPython was initially created to fill a need for an enhancement to the Python interpreter. Something useful in addition to simply running snippets of code line by line.\n" 100 | ] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "metadata": { 105 | "slideshow": { 106 | "slide_type": "slide" 107 | } 108 | }, 109 | "source": [ 110 | "## How IPython went above and beyond a regular REPL\n", 111 | "1. Retain access to the environment's state\n", 112 | "* Include a control system\n", 113 | "* Perform OS-level actions\n", 114 | "* Perform introspection and help\n", 115 | "* Execute and debug apps within its interface" 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "metadata": { 121 | "slideshow": { 122 | "slide_type": "fragment" 123 | } 124 | }, 125 | "source": [ 126 | "As an aside, it was so good at OS-level actions that some Windows users adopted it in place of the native command prompt." 127 | ] 128 | }, 129 | { 130 | "cell_type": "markdown", 131 | "metadata": { 132 | "slideshow": { 133 | "slide_type": "slide" 134 | } 135 | }, 136 | "source": [ 137 | "## When the IPython enhanced interpreter went to a browser-based project doing the same stuff\n", 138 | "In December of 2011, Perez, Brian Granger and Min Ragan-Kelley figured out a way to convert the interactive shell into a browser with \"cells\" where code is executed. Also, there are \"cells\" specifically for markdown text." 139 | ] 140 | }, 141 | { 142 | "cell_type": "markdown", 143 | "metadata": { 144 | "slideshow": { 145 | "slide_type": "slide" 146 | } 147 | }, 148 | "source": [ 149 | "## The R kernel is a younger cousing of the python kernel\n", 150 | "\n", 151 | "The R kernel (IRkernel) is a much, much newer project with it's **first** release of 0.1 on Mar 5, 2015 (source: https://github.com/IRkernel/IRkernel/releases)\n", 152 | "* **No magics** ((the ability to leverage other languages/process types in IPython) for the R kernel and probably never...they'd have to resolve the modulus to magic indicator conflict (`%%`)" 153 | ] 154 | }, 155 | { 156 | "cell_type": "markdown", 157 | "metadata": { 158 | "slideshow": { 159 | "slide_type": "slide" 160 | } 161 | }, 162 | "source": [ 163 | "* However, R code can be run from within a python flavored notebook using a python library `rpy2` and is currently a common option for **combining the IPython features with R** in academic pubs" 164 | ] 165 | }, 166 | { 167 | "cell_type": "markdown", 168 | "metadata": { 169 | "slideshow": { 170 | "slide_type": "slide" 171 | } 172 | }, 173 | "source": [ 174 | "" 175 | ] 176 | }, 177 | { 178 | "cell_type": "markdown", 179 | "metadata": { 180 | "slideshow": { 181 | "slide_type": "notes" 182 | } 183 | }, 184 | "source": [ 185 | "The jupyter **notebook above** can be found at the github repo [here](https://github.com/michhar/rpy2_sample_notebooks). There is also a [blog](http://blog.revolutionanalytics.com/2016/01/pipelining-r-python.html) about the idea of pipelining R and python in practice (**caveat**: don't try pipelining on big data; useful for prototyping or Mb - Gb datasets)." 186 | ] 187 | }, 188 | { 189 | "cell_type": "markdown", 190 | "metadata": { 191 | "slideshow": { 192 | "slide_type": "slide" 193 | } 194 | }, 195 | "source": [ 196 | "# Perspectives" 197 | ] 198 | }, 199 | { 200 | "cell_type": "markdown", 201 | "metadata": { 202 | "slideshow": { 203 | "slide_type": "slide" 204 | } 205 | }, 206 | "source": [ 207 | "## On the jupyter project's hopeful future in data science\n", 208 | "\n", 209 | "> \"Jupyter is an amazing project that feeds and rides the rising wave of data science.\" \n", 210 | "- quote from article by Alex Perrier [here](https://www.opendatascience.com/blog/jupyter-zeppelin-beaker-the-rise-of-the-notebooks/)" 211 | ] 212 | }, 213 | { 214 | "cell_type": "markdown", 215 | "metadata": { 216 | "collapsed": true, 217 | "slideshow": { 218 | "slide_type": "slide" 219 | } 220 | }, 221 | "source": [ 222 | "## Resources\n", 223 | "\n", 224 | "* Markdown\n", 225 | " 1. Markdown cheat sheet: https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet\n", 226 | " * John Gruber's markdown guide: http://daringfireball.net/projects/markdown/syntax\n", 227 | "* Original IPython Article by F. Perez: https://web.archive.org/web/20100602042637/http:/fperez.org/papers/ipython07_pe-gr_cise.pdf\n", 228 | "\n" 229 | ] 230 | } 231 | ], 232 | "metadata": { 233 | "kernelspec": { 234 | "display_name": "R", 235 | "language": "R", 236 | "name": "ir" 237 | }, 238 | "language_info": { 239 | "codemirror_mode": "r", 240 | "file_extension": ".r", 241 | "mimetype": "text/x-r-source", 242 | "name": "R", 243 | "pygments_lexer": "r", 244 | "version": "3.2.2" 245 | }, 246 | "nav_menu": {}, 247 | "toc": { 248 | "navigate_menu": true, 249 | "number_sections": true, 250 | "sideBar": true, 251 | "threshold": 6, 252 | "toc_cell": false, 253 | "toc_section_display": "block", 254 | "toc_window_display": false 255 | } 256 | }, 257 | "nbformat": 4, 258 | "nbformat_minor": 0 259 | } 260 | -------------------------------------------------------------------------------- /02_Jupyter notebooks - the inner workings.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "slideshow": { 7 | "slide_type": "slide" 8 | } 9 | }, 10 | "source": [ 11 | "# Jupyter notebooks\n", 12 | "\n", 13 | "How does it work?" 14 | ] 15 | }, 16 | { 17 | "cell_type": "markdown", 18 | "metadata": { 19 | "slideshow": { 20 | "slide_type": "slide" 21 | } 22 | }, 23 | "source": [ 24 | "> The Jupyter Notebook is a web application that allows you to create and share documents that contain live code, equations, visualizations and explanatory text. Uses include: data cleaning and transformation, numerical simulation, statistical modeling, machine learning and much more.\n", 25 | " - http://jupyter.org/\n", 26 | " \n", 27 | "\n", 28 | " \n" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": { 34 | "slideshow": { 35 | "slide_type": "slide" 36 | } 37 | }, 38 | "source": [ 39 | "" 40 | ] 41 | }, 42 | { 43 | "cell_type": "markdown", 44 | "metadata": { 45 | "slideshow": { 46 | "slide_type": "slide" 47 | } 48 | }, 49 | "source": [ 50 | "# The Jupyter project\n", 51 | "\n", 52 | "Jupyter is an open source project\n", 53 | "\n", 54 | "* Written in python\n", 55 | "* Kernels enable connectivity to other languages\n", 56 | "\n", 57 | "Dependencies\n", 58 | "\n", 59 | "* The kernel and target languages communicates using ZeroMQ message queuing engine\n", 60 | "\n", 61 | "Installation\n", 62 | "\n", 63 | "* An easy way to get Jupyter is to install the Anaconda distribution\n" 64 | ] 65 | }, 66 | { 67 | "cell_type": "markdown", 68 | "metadata": {}, 69 | "source": [ 70 | "# ZeroMQ\n", 71 | "\n", 72 | "![](images/02_Jupyter the inner workings/zeromq.png)" 73 | ] 74 | }, 75 | { 76 | "cell_type": "markdown", 77 | "metadata": { 78 | "slideshow": { 79 | "slide_type": "slide" 80 | } 81 | }, 82 | "source": [ 83 | "# How does Jupyter work?\n", 84 | "\n", 85 | "\n", 86 | "\n" 87 | ] 88 | }, 89 | { 90 | "cell_type": "markdown", 91 | "metadata": { 92 | "slideshow": { 93 | "slide_type": "slide" 94 | } 95 | }, 96 | "source": [ 97 | "# How does Jupyter work with R?\n", 98 | "\n", 99 | "\n", 100 | "\n", 101 | "\n" 102 | ] 103 | }, 104 | { 105 | "cell_type": "markdown", 106 | "metadata": { 107 | "slideshow": { 108 | "slide_type": "slide" 109 | } 110 | }, 111 | "source": [ 112 | "# IRKernel\n", 113 | "\n", 114 | "* IRKernel is the most widely used kernel\n", 115 | "* This communicates between R and ZeroMQ\n" 116 | ] 117 | }, 118 | { 119 | "cell_type": "markdown", 120 | "metadata": { 121 | "slideshow": { 122 | "slide_type": "slide" 123 | } 124 | }, 125 | "source": [ 126 | "# Installing Jupyter\n", 127 | "\n", 128 | "Several kernels exist for R. The most widely used is IRKernel\n", 129 | "\n", 130 | "* https://irkernel.github.io/\n", 131 | "\n", 132 | "Installation of the IRKernel" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": 1, 138 | "metadata": { 139 | "collapsed": false 140 | }, 141 | "outputs": [], 142 | "source": [ 143 | "# install.packages(\n", 144 | "# c('rzmq','repr','IRkernel','IRdisplay'), \n", 145 | "# repos = c('http://irkernel.github.io/', \n", 146 | "# getOption('repos'))\n", 147 | "#)\n" 148 | ] 149 | }, 150 | { 151 | "cell_type": "markdown", 152 | "metadata": {}, 153 | "source": [ 154 | "Connect R to IRKernel" 155 | ] 156 | }, 157 | { 158 | "cell_type": "code", 159 | "execution_count": 2, 160 | "metadata": { 161 | "collapsed": true 162 | }, 163 | "outputs": [], 164 | "source": [ 165 | "# IRkernel::installspec()\n" 166 | ] 167 | }, 168 | { 169 | "cell_type": "markdown", 170 | "metadata": { 171 | "slideshow": { 172 | "slide_type": "slide" 173 | } 174 | }, 175 | "source": [ 176 | "# Jupyter is a single user environment\n", 177 | "\n", 178 | "\n", 179 | "* By default, Jupyter only exposes localhost\n", 180 | "* It is possible to open SSH or HTTPS access to a remote machine\n", 181 | "* However, this is only for a single user\n", 182 | "\n", 183 | "The solution is to use Jupyter Hub\n", 184 | "\n", 185 | "\n", 186 | "\n", 187 | "\n", 188 | "\n" 189 | ] 190 | }, 191 | { 192 | "cell_type": "markdown", 193 | "metadata": { 194 | "collapsed": false, 195 | "slideshow": { 196 | "slide_type": "slide" 197 | } 198 | }, 199 | "source": [ 200 | "# Jupyter Hub\n", 201 | "\n", 202 | "\n" 203 | ] 204 | }, 205 | { 206 | "cell_type": "markdown", 207 | "metadata": { 208 | "slideshow": { 209 | "slide_type": "slide" 210 | } 211 | }, 212 | "source": [ 213 | "# Jupyter Hub\n", 214 | "\n", 215 | "A multi-user server\n", 216 | "\n", 217 | "* manages and proxies multiple instances of the single-user IPython Jupyter notebook server.\n", 218 | "\n", 219 | "Three actors:\n", 220 | "\n", 221 | "* multi-user Hub (tornado process)\n", 222 | "* configurable http proxy (node-http-proxy)\n", 223 | "* multiple single-user IPython notebook servers (Python/IPython/tornado)\n", 224 | "\n", 225 | "Basic principles:\n", 226 | "\n", 227 | "* Hub spawns proxy\n", 228 | "* Proxy forwards ~all requests to hub by default\n", 229 | "* Hub handles login, and spawns single-user servers on demand\n", 230 | "* Hub configures proxy to forward url prefixes to single-user servers\n" 231 | ] 232 | }, 233 | { 234 | "cell_type": "markdown", 235 | "metadata": { 236 | "collapsed": true 237 | }, 238 | "source": [ 239 | "# How we manage this workshop\n", 240 | "\n", 241 | "* Create a Data Science virtual machine on Azure\n", 242 | " - Select the Linux version\n", 243 | " - This contains Jupyter Notebooks as well as Jupyter Hub\n", 244 | " \n", 245 | "* Create content and publish on github\n", 246 | "\n", 247 | "* git pull content to VM\n", 248 | "\n", 249 | "* Create users\n", 250 | "\n", 251 | "* Start Juptyer Hub" 252 | ] 253 | } 254 | ], 255 | "metadata": { 256 | "kernelspec": { 257 | "display_name": "R", 258 | "language": "R", 259 | "name": "ir" 260 | }, 261 | "language_info": { 262 | "codemirror_mode": "r", 263 | "file_extension": ".r", 264 | "mimetype": "text/x-r-source", 265 | "name": "R", 266 | "pygments_lexer": "r", 267 | "version": "3.2.2" 268 | }, 269 | "nav_menu": {}, 270 | "toc": { 271 | "navigate_menu": true, 272 | "number_sections": true, 273 | "sideBar": true, 274 | "threshold": 6, 275 | "toc_cell": false, 276 | "toc_section_display": "block", 277 | "toc_window_display": false 278 | } 279 | }, 280 | "nbformat": 4, 281 | "nbformat_minor": 0 282 | } 283 | -------------------------------------------------------------------------------- /04_Reproducible research.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "slideshow": { 7 | "slide_type": "slide" 8 | } 9 | }, 10 | "source": [ 11 | "# Reproducible research" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "metadata": { 17 | "slideshow": { 18 | "slide_type": "slide" 19 | } 20 | }, 21 | "source": [ 22 | "# Definition\n", 23 | "\n", 24 | "> The goal of reproducible research is to tie specific instructions to data analysis and experimental data so that scholarship can be recreated, better understood and verified.\n", 25 | "\n", 26 | "Source: [CRAN Taskview](https://cran.r-project.org/web/views/ReproducibleResearch.html)" 27 | ] 28 | }, 29 | { 30 | "cell_type": "markdown", 31 | "metadata": { 32 | "slideshow": { 33 | "slide_type": "slide" 34 | } 35 | }, 36 | "source": [ 37 | "# Literate programming\n", 38 | "\n", 39 | "* A new approach to programming, introduced by Donald Knuth\n", 40 | "* Programme is in natural language, e.g. English\n", 41 | "* Interspersed with macros that contain machine instructions\n" 42 | ] 43 | }, 44 | { 45 | "cell_type": "markdown", 46 | "metadata": { 47 | "slideshow": { 48 | "slide_type": "slide" 49 | } 50 | }, 51 | "source": [ 52 | "# Example of LaTEX in text\n", 53 | "\n", 54 | "```\n", 55 | "The purpose of wc is to count lines, words, and/or characters in a list of files. The\n", 56 | "number of lines in a file is ......../more explanations/\n", 57 | "\n", 58 | "Here, then, is an overview of the file wc.c that is defined by the noweb program wc.nw:\n", 59 | "```\n", 60 | "```c\n", 61 | " <<*>>=\n", 62 | " <
>\n", 63 | " <>\n", 64 | " <>\n", 65 | " <>\n", 66 | " <>\n", 67 | " @\n", 68 | "```\n", 69 | "\n", 70 | "```\n", 71 | "We must include the standard I/O definitions, since we want to send formatted output\n", 72 | "to stdout and stderr.\n", 73 | "```\n", 74 | "```c\n", 75 | " <
>=\n", 76 | " #include \n", 77 | " @\n", 78 | "```" 79 | ] 80 | }, 81 | { 82 | "cell_type": "markdown", 83 | "metadata": { 84 | "slideshow": { 85 | "slide_type": "slide" 86 | } 87 | }, 88 | "source": [ 89 | "# From LaTex to Notebooks\n", 90 | "\n", 91 | "First there was LaTex\n", 92 | "\n", 93 | "Then knitr emerged, followed by rmarkdown\n", 94 | "\n", 95 | "Jupyter Notebooks followed a different evolutionary path" 96 | ] 97 | }, 98 | { 99 | "cell_type": "markdown", 100 | "metadata": { 101 | "slideshow": { 102 | "slide_type": "slide" 103 | } 104 | }, 105 | "source": [ 106 | "# Markdown vs Notebooks\n", 107 | "\n", 108 | "**knitr and rmardown** | **Notebooks**\n", 109 | "-------- | ---------\n", 110 | "Runs in IDE | Runs in web browser\n", 111 | "R embedded in markdown | Markdown and R both embedded as cells\n", 112 | "Static | Interactive\n", 113 | "Better for reporting | Better for exploration, prototyping\n", 114 | "\n", 115 | "You can use both systems for creating automated reporting:\n", 116 | "\n", 117 | "* With knitr use `knit()` and family\n", 118 | "* With notebooks use `nbconvert` on the command line" 119 | ] 120 | } 121 | ], 122 | "metadata": { 123 | "kernelspec": { 124 | "display_name": "R", 125 | "language": "R", 126 | "name": "ir" 127 | }, 128 | "language_info": { 129 | "codemirror_mode": "r", 130 | "file_extension": ".r", 131 | "mimetype": "text/x-r-source", 132 | "name": "R", 133 | "pygments_lexer": "r", 134 | "version": "3.2.2" 135 | }, 136 | "nav_menu": {}, 137 | "toc": { 138 | "navigate_menu": true, 139 | "number_sections": true, 140 | "sideBar": true, 141 | "threshold": 6, 142 | "toc_cell": false, 143 | "toc_section_display": "block", 144 | "toc_window_display": false 145 | } 146 | }, 147 | "nbformat": 4, 148 | "nbformat_minor": 0 149 | } 150 | -------------------------------------------------------------------------------- /06_Jupyter notebooks on Azure.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "slideshow": { 7 | "slide_type": "slide" 8 | } 9 | }, 10 | "source": [ 11 | "# Jupyter notebooks on Azure" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "metadata": { 17 | "collapsed": true, 18 | "slideshow": { 19 | "slide_type": "slide" 20 | } 21 | }, 22 | "source": [ 23 | "# Azure is the Microsoft cloud\n", 24 | "\n", 25 | "Multiple components:\n", 26 | "\n", 27 | "* Platform as a service (PAAS)\n", 28 | " \n", 29 | "* Software as a service (SAAS)\n", 30 | "\n" 31 | ] 32 | }, 33 | { 34 | "cell_type": "markdown", 35 | "metadata": { 36 | "slideshow": { 37 | "slide_type": "slide" 38 | } 39 | }, 40 | "source": [ 41 | "# Infrastructure as a service (IAAS)\n", 42 | "\n", 43 | " - Virtual machines\n", 44 | " * Linux, Windows\n", 45 | " * Hadoop, e.g. HDInsights\n", 46 | " * Data Science virtual machine\n", 47 | " * etc\n", 48 | " - Storage\n", 49 | " - Use PAAS to scale out on demand but maintain full control\n", 50 | " " 51 | ] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "metadata": { 56 | "slideshow": { 57 | "slide_type": "slide" 58 | } 59 | }, 60 | "source": [ 61 | "# Azure services\n", 62 | "\n", 63 | "![](images/06_Notebooks_on_Azure/Azure_services.jpg)" 64 | ] 65 | }, 66 | { 67 | "cell_type": "markdown", 68 | "metadata": { 69 | "slideshow": { 70 | "slide_type": "slide" 71 | } 72 | }, 73 | "source": [ 74 | "# Cortana Intelligence Suite\n", 75 | "\n", 76 | "![](images/06_Notebooks_on_Azure/CIS.png)" 77 | ] 78 | }, 79 | { 80 | "cell_type": "markdown", 81 | "metadata": { 82 | "slideshow": { 83 | "slide_type": "notes" 84 | } 85 | }, 86 | "source": [ 87 | "Cortana Intelligence Suite (CIS) is a set of services that allows you to build intelligence into applications\n", 88 | "\n", 89 | "* Azure Machine Learning Studio\n", 90 | "* Event hub\n", 91 | "* streaming analytics\n", 92 | "* Azure data factory\n", 93 | "* PowerBI\n", 94 | "* Microsoft R Server" 95 | ] 96 | }, 97 | { 98 | "cell_type": "markdown", 99 | "metadata": { 100 | "slideshow": { 101 | "slide_type": "slide" 102 | } 103 | }, 104 | "source": [ 105 | "# Jupyter in Azure\n", 106 | "\n", 107 | "Jupyter allows you to expose R (and other languages) in a browser, giving a light-weight IDE experience." 108 | ] 109 | }, 110 | { 111 | "cell_type": "markdown", 112 | "metadata": { 113 | "slideshow": { 114 | "slide_type": "fragment" 115 | } 116 | }, 117 | "source": [ 118 | "This is useful in many applications. Two examples:\n", 119 | "\n", 120 | "* [Azure Machine Learning Studio](https://studio.azureml.net)\n", 121 | "* HD Insights (Hadoop)" 122 | ] 123 | }, 124 | { 125 | "cell_type": "markdown", 126 | "metadata": { 127 | "slideshow": { 128 | "slide_type": "fragment" 129 | } 130 | }, 131 | "source": [ 132 | "Azure also exposes a dedicated Jupyter service\n", 133 | "\n", 134 | "* [Azure notebook service](https://notebooks.azure.com)" 135 | ] 136 | }, 137 | { 138 | "cell_type": "markdown", 139 | "metadata": { 140 | "slideshow": { 141 | "slide_type": "fragment" 142 | } 143 | }, 144 | "source": [ 145 | "Finally, you can get a working Jupyter installation with the **Data Science Virtual machine**\n", 146 | "\n", 147 | "* https://azure.microsoft.com/en-us/documentation/articles/machine-learning-data-science-provision-vm/" 148 | ] 149 | }, 150 | { 151 | "cell_type": "markdown", 152 | "metadata": { 153 | "slideshow": { 154 | "slide_type": "slide" 155 | } 156 | }, 157 | "source": [ 158 | "# The data science virtual machine\n", 159 | "\n", 160 | "The Data Science VM is a ready built environment that contains:\n", 161 | "\n", 162 | "* Microsoft R Server Developer Edition\n", 163 | "* Anaconda Python distribution\n", 164 | "* Visual Studio Community Edition\n", 165 | "* Power BI desktop\n", 166 | "* SQL Server Express edition\n", 167 | "* Azure SDK\n", 168 | "* and more" 169 | ] 170 | }, 171 | { 172 | "cell_type": "markdown", 173 | "metadata": { 174 | "slideshow": { 175 | "slide_type": "fragment" 176 | } 177 | }, 178 | "source": [ 179 | "Available on Windows as well as Linux (CentOS 7)\n", 180 | "\n", 181 | "* https://azure.microsoft.com/en-us/marketplace/partners/microsoft-ads/standard-data-science-vm/" 182 | ] 183 | }, 184 | { 185 | "cell_type": "markdown", 186 | "metadata": { 187 | "slideshow": { 188 | "slide_type": "slide" 189 | } 190 | }, 191 | "source": [ 192 | "# Demonstration of Azure ML Studio and Jupyter\n", 193 | "\n", 194 | "" 195 | ] 196 | }, 197 | { 198 | "cell_type": "markdown", 199 | "metadata": { 200 | "slideshow": { 201 | "slide_type": "slide" 202 | } 203 | }, 204 | "source": [ 205 | "# Questions?\n", 206 | "\n" 207 | ] 208 | } 209 | ], 210 | "metadata": { 211 | "kernelspec": { 212 | "display_name": "R", 213 | "language": "R", 214 | "name": "ir" 215 | }, 216 | "language_info": { 217 | "codemirror_mode": "r", 218 | "file_extension": ".r", 219 | "mimetype": "text/x-r-source", 220 | "name": "R", 221 | "pygments_lexer": "r", 222 | "version": "3.2.2" 223 | }, 224 | "nav_menu": {}, 225 | "toc": { 226 | "navigate_menu": true, 227 | "number_sections": true, 228 | "sideBar": true, 229 | "threshold": 6, 230 | "toc_cell": false, 231 | "toc_section_display": "block", 232 | "toc_window_display": false 233 | } 234 | }, 235 | "nbformat": 4, 236 | "nbformat_minor": 0 237 | } 238 | -------------------------------------------------------------------------------- /07_Teaching with notebooks.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "slideshow": { 7 | "slide_type": "slide" 8 | } 9 | }, 10 | "source": [ 11 | "# Teaching, Training and Workshoping with Jupyter Notebooks" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "metadata": { 17 | "slideshow": { 18 | "slide_type": "slide" 19 | } 20 | }, 21 | "source": [ 22 | "## Before you start\n", 23 | "* Is it a course, workshop or for a colleague down the road?\n", 24 | " * local vs. cloud\n", 25 | " * singe vs. multi-tenant\n", 26 | " * persistent\n", 27 | "* Audience - how much code should I have?\n", 28 | "* Will this be a presentation as well?" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": { 34 | "slideshow": { 35 | "slide_type": "slide" 36 | } 37 | }, 38 | "source": [ 39 | "## Designing interesting notebooks\n", 40 | "* Motivation - quick exercise (\"teaser code\") with engaging plot\n", 41 | "* Embed images often\n", 42 | "* Exercises - often and small\n", 43 | "* Bonus exercises" 44 | ] 45 | }, 46 | { 47 | "cell_type": "markdown", 48 | "metadata": { 49 | "slideshow": { 50 | "slide_type": "slide" 51 | } 52 | }, 53 | "source": [ 54 | "## Tips: beyond notebooks\n", 55 | "* Pre and post surveys\n", 56 | "* Sticky notes" 57 | ] 58 | }, 59 | { 60 | "cell_type": "markdown", 61 | "metadata": { 62 | "collapsed": true, 63 | "slideshow": { 64 | "slide_type": "slide" 65 | } 66 | }, 67 | "source": [ 68 | "## Additional thoughts\n", 69 | "\n", 70 | "* Think about code cells and markdown cells as if they would be a slide in a presentation" 71 | ] 72 | } 73 | ], 74 | "metadata": { 75 | "kernelspec": { 76 | "display_name": "R", 77 | "language": "R", 78 | "name": "ir" 79 | }, 80 | "language_info": { 81 | "codemirror_mode": "r", 82 | "file_extension": ".r", 83 | "mimetype": "text/x-r-source", 84 | "name": "R", 85 | "pygments_lexer": "r", 86 | "version": "3.2.2" 87 | }, 88 | "nav_menu": {}, 89 | "toc": { 90 | "navigate_menu": true, 91 | "number_sections": true, 92 | "sideBar": true, 93 | "threshold": 6, 94 | "toc_cell": false, 95 | "toc_section_display": "block", 96 | "toc_window_display": false 97 | } 98 | }, 99 | "nbformat": 4, 100 | "nbformat_minor": 0 101 | } 102 | -------------------------------------------------------------------------------- /08_Wrapup.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "slideshow": { 7 | "slide_type": "slide" 8 | } 9 | }, 10 | "source": [ 11 | "# Wrap up" 12 | ] 13 | }, 14 | { 15 | "cell_type": "markdown", 16 | "metadata": { 17 | "slideshow": { 18 | "slide_type": "slide" 19 | } 20 | }, 21 | "source": [ 22 | "\n", 23 | "You should now know:\n", 24 | "\n", 25 | "* how and when to use notebooks\n", 26 | "* how to create and use a notebook for various purposes, including reproducible research\n", 27 | "* how to effectively use notebooks for training\n", 28 | "* how to create publication ready material from a notebook\n" 29 | ] 30 | }, 31 | { 32 | "cell_type": "markdown", 33 | "metadata": { 34 | "slideshow": { 35 | "slide_type": "slide" 36 | } 37 | }, 38 | "source": [ 39 | "# Questions?" 40 | ] 41 | } 42 | ], 43 | "metadata": { 44 | "celltoolbar": "Slideshow", 45 | "kernelspec": { 46 | "display_name": "R", 47 | "language": "R", 48 | "name": "ir" 49 | }, 50 | "language_info": { 51 | "codemirror_mode": "r", 52 | "file_extension": ".r", 53 | "mimetype": "text/x-r-source", 54 | "name": "R", 55 | "pygments_lexer": "r", 56 | "version": "3.2.2" 57 | } 58 | }, 59 | "nbformat": 4, 60 | "nbformat_minor": 0 61 | } 62 | -------------------------------------------------------------------------------- /INSTALLATIONS.md: -------------------------------------------------------------------------------- 1 | ## Installation Options 2 | * CRAN 3 | * Anaconda 4 | * R-essentials (Continuum) 5 | 6 | ## CRAN 7 | Go to IRkernel github [pages](https://irkernel.github.io/) and [Installation](https://irkernel.github.io/installation/) 8 | Useful [FAQs](https://irkernel.github.io/faq/) 9 | 10 | 11 | ## Conda for R 12 | https://www.continuum.io/conda-for-R 13 | 14 | 15 | ## R-essentials from Continuum 16 | https://www.continuum.io/blog/developer/jupyter-and-conda-r 17 | -------------------------------------------------------------------------------- /INSTALLATION_ADVANCED.md: -------------------------------------------------------------------------------- 1 | ## Install notes 2 | 3 | 1. All of the commands I run in the Command Prompt (use Admin Command Prompt only when specified) 4 | 2. For python module installs I will use "pip" or "pip3" (for python3) python package manager 5 | 3. I use the word terminal and Command Prompt interchangeably (this can be generalized to unix based systems as well) 6 | 7 | ## Pre-Requisites (32-bit recommended) 8 | 9 | 1. Python 2.7 (https://www.python.org/downloads/release/python-2710/) 10 | 2. Python 3.4 or 3.5 (https://www.python.org/downloads/windows/) 11 | 3. R (I installed 3.2.2) 12 | 13 | A restart is required to use python from the command line (i.e. it adds it to path). 14 | 15 | R is not automatically added to the PATH variable. If you want to call it from the command line you must add it by: 16 | 17 | Go to Control Panel -> System and Security -> System -> Advanced system settings -> Environment Variables 18 | 19 | On the lower screen you will see "System variables". Select "Path" and then "Edit". I added these two entries: 20 | ``` 21 | "C:\Program Files\R\R-3.2.2\bin\" 22 | "C:\Program Files\R\R-3.2.2\bin\x64\" 23 | ``` 24 | (note: your path to the R executable might be different for a different version) 25 | 26 | To check your path in terminal 27 | `echo %PATH%` 28 | 29 | Python Modules Commands 30 | 1. `pip3 install jupyter notebook` 31 | 32 | ## Getting R Ready 33 | 34 | Open an R GUI (rgui.exe or RStudio) or R command line interpreter and run these commands (installs R kernel and tells jupyter about it, also installs for user and hence uses a local user R library directory): 35 | 36 | 1. `install.packages(c('rzmq', 'repr', 'IRkernel', 'IRdisplay'), repos = c('http://irkernel.github.io/', getOption('repos')))` 37 | 2. `IRkernel::installspec(user = TRUE)` 38 | 39 | Check that the IRKernel is now an option on jupyter with this command (should be one named 'ir'): 40 | 41 | `jupyter-kernelspec list` 42 | 43 | BTW: if you want additional R packages just install them with: 44 | 45 | `install.packages(, repos = "http://cran.us.r-project.org")` 46 | 47 | Start the notebook in terminal by: 48 | • this will open it up in a browser 49 | • first cd to a working directory of your choosing 50 | * `jupyter notebook` 51 | 52 | ## Troubleshooting 53 | 54 | 1. Packages not found I.e. "Warning in install.packages : package ‘IRkernel’ is not available (for R version 3.2.3)" 55 | a. e.g. package jpeg was installed by specifying a different repo: install.packages("jpeg", repos = c("http://www.rforge.net")) 56 | 2. Need some dependencies not covered by an install_github install 57 | a. e.g. package digest, uuid, evaluate (R will warn if using install.packages, but not if using install_github from devtools) 58 | 3. Update R path 59 | 4. Update lib paths 60 | a. RStudio R lib paths are different than native R has. Jupyter uses native R paths. If installing libraries with RStudio, one should make sure that path is in Rprofile.site or .Rprofile user settings file in home dir. 61 | b. I put this in an .Rprofile file that lives in my home directory to add a library path (this tells native R to also look into the library RStudio uses which I found out with .libPaths in RStudio): 62 | i. .libPaths( c( .libPaths(), "C:/Users/michhar/Documents/R/win-library/3.2") ) 63 | 5. If you have Python2 only in your notebook and you also want Python3 do this: 64 | a. (NOTE: I have the vanilla python 2.7 and 3.4 install, i.e. not anaconda or miniconda; python3 is my default python - which I set in my environment variables by placing python34 first in my path) 65 | b. (NOTE2: if you reset a path, must open a fresh command prompt to use current path settings) 66 | i. pip3 install ipython ipykernel 67 | ii. ipython3 kernel install --name python3 --display-name "Python 3" 68 | 6. If you have Python3 only in your notebook and you also want Python2 do this: 69 | a. pip install ipython ipykernel (NB: Use python27 pip!!) 70 | b. ipython2 kernel install --name python2 --display-name "Python 2" 71 | If using conda and Ressentials make sure your R version is one belonging to conda 72 | 73 | ## Alternate approaches 74 | 75 | -Docker images (will have to run VM) 76 | - https://github.com/jupyter/docker-stacks/tree/master/datascience-notebook 77 | - https://bitbucket.org/rpy2/docker-rpy2-release 78 | 79 | 80 | If I wanted R kernel system-wide I'd have to put necessary libraries in System R library folder as well as specify user = FALSE when installing kernelspec: 81 | (just note that install.packages() from within notebooks will NOT work because library path is system and notebook will NOT have permission) 82 | 83 | Here we do installs from the current working R install (whatever is on PATH). In my case it's R-3.2.2 84 | 85 | In R-3.2.2 (as admin): 86 | From admin command prompt start R: 87 | C:\Program Files\R\R-3.2.2\bin\x64\Rgui.exe 88 | 89 | Once in Rgui run these lines: 90 | ``` 91 | install.packages(c('rzmq','repr','IRkernel','IRdisplay'), lib='C:/Program Files/R/R-3.2.2/library', repos = c('http://irkernel.github.io/', getOption('repos')) 92 | 93 | library(IRdisplay) 94 | 95 | IRkernel::installspec(user = FALSE) 96 | ``` 97 | **(Notes: you may have to install some dependencies…just do this and try installspec again)** 98 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 michhar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # R Tutorial using Jupyter Notebooks for Reproducible Research 2 | * The story revolves around image processing in R 3 | 4 | ## General outline 5 | 6 | 1. Introduction, history and perspective (basically general context) 7 | 2. Jupyter notebook inner workings in the context of the R kernel (`IRkernel` package) 8 | * Tour of Notebooks and Short Image Analysis Lab 9 | * Become familiar with the anatomy of notebooks 10 | * Learn how to efficiently navigate and work with notebooks 11 | * Gain some practice using shortcuts 12 | * Perform a short image analysis lab 13 | * Reproducible research - how Jupyter and R can address this 14 | * Expanded image analysis lab 15 | * Become comfortable building out a solution in notebooks with R and making it reproducible 16 | * Gain/regain the experience of a "hackathon" style lab involving collaboration 17 | * Become more comfortable and familiar with the notebook shortcuts and tools 18 | * Get some experience doing image color quantization 19 | * Microsoft Azure and Jupyter notebooks (they've got a few services available) 20 | * Teaching, training and workshoping with Jupyter notebooks 21 | * Wrap up 22 | 23 | 24 | ## What's so special about Jupyter notebooks? 25 | 26 | * Jupyter's power is in having code, data, and text all accessible from **one file viewed in a browser**, living locally or in the cloud. 27 | * The Jupyter Project used to be part of the IPython Project and has spun off. 28 | * It supports over 40 different languages (see this [article](https://github.com/ipython/ipython/wiki/IPython-kernels-for-other-languages)) and that is actively growing. 29 | 30 | ## Text bits (non-code cells) 31 | 32 | The text in a notebook is written in the simple __markdown__ language, making it a rich format capable of "rendering" latex, links, images and even html (since we're in a browser and the R kernel let's us). 33 | 34 | ## The "new" wave on the block (at least R-flavored notebooks) 35 | 36 | Amazing fact: in 2014, there were 80,000 jupyter notebooks on github. In 2015 the number almost tripled to 230,000. This shows how popular and fast-growing the usage is in the community. 37 | 38 | - github numbers from article by Alex Perrier [here](https://www.opendatascience.com/blog/jupyter-zeppelin-beaker-the-rise-of-the-notebooks/) 39 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-slate -------------------------------------------------------------------------------- /aml_invite_users.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/aml_invite_users.png -------------------------------------------------------------------------------- /data/03_Image_Analysis_with_k-Means/r-package-downloads-2015-jan-may.csv: -------------------------------------------------------------------------------- 1 | Rpackage,Downloads 2 | Rcpp,693288 3 | ggplot2,598484 4 | stringr,543434 5 | plyr,523220 6 | digest,521344 7 | reshape2,483065 8 | colorspace,476304 9 | RColorBrewer,453858 10 | manipulate,395232 11 | scales,394389 12 | labeling,373374 13 | proto,369096 14 | munsell,368949 15 | gtable,364015 16 | dichromat,362562 17 | mime,352780 18 | RCurl,340530 19 | bitops,322743 20 | zoo,302052 21 | knitr,295528 22 | car,295156 23 | R6,284022 24 | magrittr,277844 25 | evaluate,270151 26 | httr,266488 27 | rJava,260985 28 | jsonlite,255779 29 | dplyr,246916 30 | DBI,243914 31 | highr,242289 32 | lme4,241864 33 | formatR,239541 34 | markdown,237529 35 | devtools,235868 36 | quantreg,235102 37 | Hmisc,233664 38 | SparseM,228734 39 | nloptr,223500 40 | minqa,221535 41 | caTools,220349 42 | yaml,219480 43 | MASS,214201 44 | RcppEigen,212423 45 | Formula,205511 46 | htmltools,204896 47 | pbkrtest,197163 48 | gtools,185757 49 | XML,185286 50 | mvtnorm,184257 51 | latticeExtra,177693 52 | BH,176148 53 | lazyeval,175113 54 | lattice,167153 55 | mgcv,165148 56 | assertthat,159088 57 | acepack,156624 58 | xtable,155823 59 | sandwich,152340 60 | memoise,151114 61 | roxygen2,149294 62 | sp,148749 63 | shiny,148329 64 | gdata,148243 65 | rstudioapi,147881 66 | Matrix,147174 67 | foreach,146324 68 | RJSONIO,145311 69 | e1071,143514 70 | foreign,138717 71 | brew,137563 72 | rpart,136047 73 | iterators,135679 74 | testthat,134227 75 | rmarkdown,134101 76 | rgl,131600 77 | rjson,129841 78 | gridExtra,129743 79 | xlsx,128886 80 | data.table,128729 81 | chron,128469 82 | quadprog,127616 83 | boot,126692 84 | whisker,124481 85 | codetools,124076 86 | igraph,123930 87 | RcppArmadillo,123050 88 | forecast,122511 89 | nlme,121380 90 | gplots,120695 91 | tseries,120357 92 | reshape,116186 93 | timeDate,114521 94 | psych,111415 95 | nnet,108856 96 | randomForest,106620 97 | KernSmooth,106327 98 | httpuv,105142 99 | maps,104766 100 | multcomp,101607 101 | cluster,101233 102 | xts,98603 103 | abind,98116 104 | survival,96903 105 | tm,95535 106 | mnormt,94810 107 | RSQLite,93975 108 | lmtest,92787 109 | slam,91307 110 | coda,87751 111 | maptools,87669 112 | RODBC,81511 113 | NLP,80625 114 | plotrix,80618 115 | XLConnect,80142 116 | leaps,77685 117 | rgdal,75763 118 | quantmod,71061 119 | robustbase,69871 120 | Rcmdr,69007 121 | scatterplot3d,67805 122 | kernlab,62497 123 | modeltools,60255 124 | TTR,59054 125 | vcd,56548 126 | effects,55559 127 | vegan,51073 128 | timeSeries,48932 129 | sem,43041 130 | strucchange,42796 131 | relimp,41680 132 | matrixcalc,41065 133 | fBasics,40250 134 | aplpack,37790 135 | tree,28106 136 | akima,16602 137 | -------------------------------------------------------------------------------- /images/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/.DS_Store -------------------------------------------------------------------------------- /images/00_Welcome/login.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/00_Welcome/login.png -------------------------------------------------------------------------------- /images/00_Welcome/simulate-pi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/00_Welcome/simulate-pi.png -------------------------------------------------------------------------------- /images/02_Jupyter_the_inner_workings/Notebook_sample_breast_cancer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/02_Jupyter_the_inner_workings/Notebook_sample_breast_cancer.png -------------------------------------------------------------------------------- /images/02_Jupyter_the_inner_workings/azure-notebooks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/02_Jupyter_the_inner_workings/azure-notebooks.png -------------------------------------------------------------------------------- /images/02_Jupyter_the_inner_workings/jupyter architecture 1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/02_Jupyter_the_inner_workings/jupyter architecture 1.png -------------------------------------------------------------------------------- /images/02_Jupyter_the_inner_workings/jupyter architecture 2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/02_Jupyter_the_inner_workings/jupyter architecture 2.png -------------------------------------------------------------------------------- /images/02_Jupyter_the_inner_workings/jupyter hub logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/02_Jupyter_the_inner_workings/jupyter hub logo.png -------------------------------------------------------------------------------- /images/02_Jupyter_the_inner_workings/jupyter hub.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/02_Jupyter_the_inner_workings/jupyter hub.png -------------------------------------------------------------------------------- /images/02_Jupyter_the_inner_workings/zeromq.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/02_Jupyter_the_inner_workings/zeromq.png -------------------------------------------------------------------------------- /images/03_Image_Analysis_with_k-Means/densitypolygon-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/03_Image_Analysis_with_k-Means/densitypolygon-1.png -------------------------------------------------------------------------------- /images/03_Image_Analysis_with_k-Means/rpy2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/03_Image_Analysis_with_k-Means/rpy2.png -------------------------------------------------------------------------------- /images/03_Image_Analysis_with_k-Means/segmented_bird.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/03_Image_Analysis_with_k-Means/segmented_bird.png -------------------------------------------------------------------------------- /images/03_Image_Analysis_with_k-Means/segmented_bird2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/03_Image_Analysis_with_k-Means/segmented_bird2.png -------------------------------------------------------------------------------- /images/03_Image_Analysis_with_k-Means/top-20-r-packages-machine-learning-downloads.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/03_Image_Analysis_with_k-Means/top-20-r-packages-machine-learning-downloads.jpg -------------------------------------------------------------------------------- /images/03_Image_Analysis_with_k-Means/zebrafish_brain_10x.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/03_Image_Analysis_with_k-Means/zebrafish_brain_10x.jpeg -------------------------------------------------------------------------------- /images/05_Expanded_Image_Analysis_Lab/a_query.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/05_Expanded_Image_Analysis_Lab/a_query.jpg -------------------------------------------------------------------------------- /images/05_Expanded_Image_Analysis_Lab/hummingbird_mharris.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/05_Expanded_Image_Analysis_Lab/hummingbird_mharris.jpg -------------------------------------------------------------------------------- /images/05_Expanded_Image_Analysis_Lab/segmented_bird.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/05_Expanded_Image_Analysis_Lab/segmented_bird.png -------------------------------------------------------------------------------- /images/05_Expanded_Image_Analysis_Lab/segmented_bird2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/05_Expanded_Image_Analysis_Lab/segmented_bird2.png -------------------------------------------------------------------------------- /images/05_Expanded_Image_Analysis_Lab/whidbey_mharris.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/05_Expanded_Image_Analysis_Lab/whidbey_mharris.jpg -------------------------------------------------------------------------------- /images/06_Notebooks_on_Azure/AzureML.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/06_Notebooks_on_Azure/AzureML.png -------------------------------------------------------------------------------- /images/06_Notebooks_on_Azure/Azure_conceptual_view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/06_Notebooks_on_Azure/Azure_conceptual_view.png -------------------------------------------------------------------------------- /images/06_Notebooks_on_Azure/Azure_datacenters.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/06_Notebooks_on_Azure/Azure_datacenters.png -------------------------------------------------------------------------------- /images/06_Notebooks_on_Azure/Azure_services.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/06_Notebooks_on_Azure/Azure_services.jpg -------------------------------------------------------------------------------- /images/06_Notebooks_on_Azure/Azure_services.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/06_Notebooks_on_Azure/Azure_services.png -------------------------------------------------------------------------------- /images/06_Notebooks_on_Azure/CIS.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/06_Notebooks_on_Azure/CIS.png -------------------------------------------------------------------------------- /images/06_Notebooks_on_Azure/aml_invite_users.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michhar/useR2016-tutorial-jupyter/1cb0102bd18f466dad3a33eca5c9c6df3f34d546/images/06_Notebooks_on_Azure/aml_invite_users.png -------------------------------------------------------------------------------- /notebook_basics/01.Installing stuff.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Installation tips\n", 8 | "* Easiest is to a miniconda + r-essentials install like [here](https://www.continuum.io/blog/developer/jupyter-and-conda-r) (If you want the hard way ask me later - i.e. the way where you can pick your R release version)" 9 | ] 10 | }, 11 | { 12 | "cell_type": "markdown", 13 | "metadata": {}, 14 | "source": [ 15 | "# Installing packages\n", 16 | "* A lot of the time with jupyter systems you will encounter, you will not have permission to write to the default library so do this:" 17 | ] 18 | }, 19 | { 20 | "cell_type": "code", 21 | "execution_count": null, 22 | "metadata": { 23 | "collapsed": false 24 | }, 25 | "outputs": [], 26 | "source": [ 27 | "# Check library location\n", 28 | ".libPaths()" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": null, 34 | "metadata": { 35 | "collapsed": false 36 | }, 37 | "outputs": [], 38 | "source": [ 39 | "# Add a local path (if it doesn't exist nothing will happen)\n", 40 | ".libPaths(c(.libPaths(), \"C:/Users/michhar/Documents/bin/rmds\"))\n", 41 | "\n", 42 | "# Then recheck\n", 43 | ".libPaths()" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": { 50 | "collapsed": false 51 | }, 52 | "outputs": [], 53 | "source": [ 54 | "getwd()" 55 | ] 56 | }, 57 | { 58 | "cell_type": "code", 59 | "execution_count": null, 60 | "metadata": { 61 | "collapsed": false 62 | }, 63 | "outputs": [], 64 | "source": [ 65 | "install.packages(\"ggplot2\", repos = \"http://cloud.r-project.org/\", \n", 66 | " lib = \"C:/Users/michhar/Documents/R/win-library/3.2/\")" 67 | ] 68 | }, 69 | { 70 | "cell_type": "markdown", 71 | "metadata": {}, 72 | "source": [ 73 | "### Just so you know...you can write R code in a python notebook - here are some links:\n", 74 | "\n", 75 | "(this has some advantages such as using the more feature rich IPython kernel...but if you don't care about magics and OS interaction that much don't worry about it)\n", 76 | "* http://eneskemalergin.github.io/2015/10/01/R_Magic_with_IPython/\n", 77 | "* http://blog.revolutionanalytics.com/2016/01/pipelining-r-python.html - my shameless plug for myself" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "metadata": { 83 | "collapsed": true 84 | }, 85 | "source": [ 86 | "Created by a Microsoft Employee.\n", 87 | "\t\n", 88 | "The MIT License (MIT)
\n", 89 | "Copyright (c) 2016 Micheleen Harris" 90 | ] 91 | }, 92 | { 93 | "cell_type": "code", 94 | "execution_count": null, 95 | "metadata": { 96 | "collapsed": true 97 | }, 98 | "outputs": [], 99 | "source": [] 100 | } 101 | ], 102 | "metadata": { 103 | "kernelspec": { 104 | "display_name": "R", 105 | "language": "R", 106 | "name": "ir" 107 | }, 108 | "language_info": { 109 | "codemirror_mode": "r", 110 | "file_extension": ".r", 111 | "mimetype": "text/x-r-source", 112 | "name": "R", 113 | "pygments_lexer": "r", 114 | "version": "3.2.3" 115 | } 116 | }, 117 | "nbformat": 4, 118 | "nbformat_minor": 0 119 | } 120 | -------------------------------------------------------------------------------- /notebook_basics/02.General anatomy.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# General Jupyter Notebook Anatomy\n", 8 | "### Super quickstart:\n", 9 | " 1. Up and down arrows take you through each \"cell\" of the notebook (a cell == a chunk in Rmd)\n", 10 | " * To run a cell, either the text (markdown, as we'll see) or code, it's **`Shift-Enter`** (`Shift` and `Enter` at same time)" 11 | ] 12 | }, 13 | { 14 | "cell_type": "markdown", 15 | "metadata": {}, 16 | "source": [ 17 | "## Disclaimers:\n", 18 | "1. Notebooks are no substitute for an IDE for developing apps (yet).\n", 19 | "* Notebooks are not suitable for debugging code (yet).\n", 20 | "* They might be a substitute for r-markdown, unless you want auto-generated reporting.\n", 21 | "\n", 22 | "---\n", 23 | "\n", 24 | "1. My main use of notebooks are for interactive teaching mostly and as a playground for some code that I might like to share at some point (I can add useful and pretty markup text, pics, videos, etc).\n", 25 | "* I'm a fan also because github render's ipynb files nicely (even better than r-markdown for some reason).\n", 26 | "* Static versions are still very helpful to follow along to.\n", 27 | "* If the correct `latex` libraries are installed, beautiful pdfs can be generated `latex` style." 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "metadata": {}, 33 | "source": [ 34 | "## Intro to usage" 35 | ] 36 | }, 37 | { 38 | "cell_type": "markdown", 39 | "metadata": {}, 40 | "source": [ 41 | "### In this figure are a few *labels* of notebook parts I will refer to\n", 42 | "![img](imgs/B01727_03.png)" 43 | ] 44 | }, 45 | { 46 | "cell_type": "markdown", 47 | "metadata": {}, 48 | "source": [ 49 | "### This is a little diagram of the anatomy of the notebook *toolbar*\n", 50 | "\n", 51 | "\"Smiley" 52 | ] 53 | }, 54 | { 55 | "cell_type": "markdown", 56 | "metadata": {}, 57 | "source": [ 58 | "### Try out these steps as you read through this:\n", 59 | "> 1. You can click in the Notebook Name area and rename your notebook\n", 60 | "2. Your notebook is saved to the directory you started this server from (as a general rule though I download the notebook at intervals in addition to saving it just in case)\n", 61 | "3. To download the notebook, go to the Menu bar -> File -> Download As -> IPython Notebook (.ipynb) (if you do this you will see you can actually download in many different formats)\n", 62 | "4. In the toolbar you can add a new cell with the +, run the notebook (the triangle button - might look different in your notebook like a triangle with a line after it)\n", 63 | "5. Cell type defaults to Code. You can change this to Markdown if you want to take notes (markdown is it's own language for which you can find [guides](http://rmarkdown.rstudio.com/authoring_basics.html)). Markdown is what all the text here is written in, so double click on this text to see the raw markdown. Also, for whatever reason you can embed any html you want (good way to include pics). Aaaaaand, LaTeX equations seem to render just fine with some exceptions.\n", 64 | "6. Code cell types are grey\n", 65 | "7. Most importantly, to run a cell hit the run button in toolbar or just type Shift-Enter (try!)" 66 | ] 67 | }, 68 | { 69 | "cell_type": "code", 70 | "execution_count": null, 71 | "metadata": { 72 | "collapsed": true 73 | }, 74 | "outputs": [], 75 | "source": [] 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "metadata": {}, 80 | "source": [ 81 | "## Shortcuts!!!\n", 82 | "* A complete list is [here](https://sowingseasons.com/blog/reference/2016/01/jupyter-keyboard-shortcuts/23298516), but these are my favorites:\n", 83 | "\n", 84 | "Mode | What | Shortcut\n", 85 | "------------- | ------------- | -------------\n", 86 | "Command (Press `Esc` to enter) | Run cell | Shift-Enter\n", 87 | "Command | Add cell below | B\n", 88 | "Command | Add cell above | A\n", 89 | "Command | Delete a cell | d-d\n", 90 | "Command | Turn code cell to markdown cell | M\n", 91 | "Command | Turn markdown cell to code cell | Y\n", 92 | "Command | Go into edit mode | Enter\n", 93 | "Edit (Press `Enter` to go into a cell) | Run cell | Shift-Enter\n", 94 | "Edit | Indent | Clrl-]\n", 95 | "Edit | Unindent | Ctrl-[\n", 96 | "Edit | Comment/uncomment section toggle | Ctrl-/\n", 97 | "Edit | Function introspection | Tab\n", 98 | "\n", 99 | "### Try some below" 100 | ] 101 | }, 102 | { 103 | "cell_type": "markdown", 104 | "metadata": {}, 105 | "source": [ 106 | "Convert the next cell (a code cell) into markdown (**`Esc`** to make sure you're in command mode and **`M`** for markdown) (Don't forget to hit the **`Shift-Enter`** shortcut to run a cell):" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": null, 112 | "metadata": { 113 | "ExecuteTime": { 114 | "end_time": "2016-06-26T12:42:25.162682", 115 | "start_time": "2016-06-26T19:42:25.144Z" 116 | }, 117 | "collapsed": true 118 | }, 119 | "outputs": [], 120 | "source": [ 121 | "# turn this comment from code to a heading 1 (h1)" 122 | ] 123 | }, 124 | { 125 | "cell_type": "markdown", 126 | "metadata": {}, 127 | "source": [ 128 | "This sentence is one cell (a markdown cell) so please add a new cell below this one (**`Esc`** to make sure you're in command mode and **`B`** for below)." 129 | ] 130 | }, 131 | { 132 | "cell_type": "markdown", 133 | "metadata": {}, 134 | "source": [ 135 | "Comment/not comment toggle. Run the cell with **`Shift-Enter`**. Next, uncomment the second line of code in the following code cell (**`Ctrl-/`** which is `Ctrl` and `/` together):" 136 | ] 137 | }, 138 | { 139 | "cell_type": "code", 140 | "execution_count": null, 141 | "metadata": { 142 | "ExecuteTime": { 143 | "end_time": "2016-06-26T12:49:38.909933", 144 | "start_time": "2016-06-26T19:49:38.468Z" 145 | }, 146 | "collapsed": false 147 | }, 148 | "outputs": [], 149 | "source": [ 150 | "library(ggplot2)\n", 151 | "\n", 152 | "# mtcars$am <- factor(mtcars$am)\n", 153 | "\n", 154 | "ggplot(mtcars, aes(x = mpg, y = hp, color = am)) + geom_point()" 155 | ] 156 | }, 157 | { 158 | "cell_type": "markdown", 159 | "metadata": {}, 160 | "source": [ 161 | "## Latex/markdown in notebooks" 162 | ] 163 | }, 164 | { 165 | "cell_type": "code", 166 | "execution_count": null, 167 | "metadata": { 168 | "collapsed": false 169 | }, 170 | "outputs": [], 171 | "source": [ 172 | "\n", 173 | "#### OK, change this cell to markdown to see some examples (you'll recognize this if you speak markdown)\n", 174 | "# This will be Heading1\n", 175 | "1. first thing\n", 176 | "* second thing\n", 177 | "* third thing\n", 178 | "\n", 179 | "A horizontal rule:\n", 180 | "\n", 181 | "---\n", 182 | "> Indented text\n", 183 | "\n", 184 | "Code snippet:\n", 185 | "\n", 186 | "```r\n", 187 | "df <- data.frame()\n", 188 | "```\n", 189 | "\n", 190 | "LaTeX inline equation:\n", 191 | "\n", 192 | "$\\Delta =\\sum_{i=1}^N w_i (x_i - \\bar{x})^2$\n", 193 | "\n", 194 | "LaTeX table:\n", 195 | "\n", 196 | "First Header | Second Header\n", 197 | "------------- | -------------\n", 198 | "Content Cell | Content Cell\n", 199 | "Content Cell | Content Cell\n", 200 | "\n", 201 | "HTML:\n", 202 | "\n", 203 | "\"You" 204 | ] 205 | }, 206 | { 207 | "cell_type": "markdown", 208 | "metadata": {}, 209 | "source": [ 210 | "### Try out a code cell (run shortcut - Shift-Enter)" 211 | ] 212 | }, 213 | { 214 | "cell_type": "code", 215 | "execution_count": null, 216 | "metadata": { 217 | "ExecuteTime": { 218 | "end_time": "2016-06-26T12:51:40.265597", 219 | "start_time": "2016-06-26T19:51:40.222Z" 220 | }, 221 | "collapsed": false 222 | }, 223 | "outputs": [], 224 | "source": [ 225 | "paste0(1:10)\n", 226 | "print(sprintf(\"Your current R version is %s\", R.version.string))" 227 | ] 228 | }, 229 | { 230 | "cell_type": "markdown", 231 | "metadata": {}, 232 | "source": [ 233 | "## Open/upload/new\n", 234 | "\n", 235 | "1. **As you can see on your jupyter homepage you can open up any notebook**\n", 236 | "\n", 237 | " NB: You can return to the homepage by clicking the Jupyter icon in the very upper left corner at any time
\n", 238 | "\n", 239 | "2. **You can also Upload a notebook (button on upper right)**\n", 240 | "\n", 241 | " *

\n", 242 | "\n", 243 | "3. **As well as start a new notebook with a specific kernel (button to the right of Upload)**\n", 244 | "\n", 245 | " * " 246 | ] 247 | }, 248 | { 249 | "cell_type": "markdown", 250 | "metadata": {}, 251 | "source": [ 252 | "### Note about In/Out\n", 253 | "So, what's that number after `In` or `Out`? That's the order of running this cell relative to other cells (useful for keeping track of what order cells have been run). When you save this notebook that number along with any output shown will also be saved. To reset a notebook go to Cell -> All Output -> Clear and then Save it." 254 | ] 255 | }, 256 | { 257 | "cell_type": "markdown", 258 | "metadata": {}, 259 | "source": [ 260 | "## Viewing\n", 261 | "\n", 262 | "You can do something like this to render a publicly available notebook on github statically (this I do as a backup for presentations and course stuff):\n", 263 | "\n", 264 | "```\n", 265 | "http://nbviewer.jupyter.org/github///blob/master/.ipynb\n", 266 | "```\n", 267 | "like:
\n", 268 | "http://nbviewer.jupyter.org/github/michhar/rpy2_sample_notebooks/blob/master/TestingRpy2.ipynb\n", 269 | "\n", 270 | "
\n", 271 | "Also, you can upload or start a new interactive, free notebook by going here:
\n", 272 | "https://tmpnb.org\n", 273 | "
\n", 274 | "\n", 275 | "



\n", 276 | "Free tier account with Azure Machine Learning Studio (now has R-flavored notebooks)" 277 | ] 278 | }, 279 | { 280 | "cell_type": "markdown", 281 | "metadata": {}, 282 | "source": [ 283 | "> The nifty thing about Jupyter notebooks (and the .ipynb files which you can download and upload) is that you can share these. They are just written in JSON language. I put them up in places like GitHub and point people in that direction. \n", 284 | "\n", 285 | "> Some people (like [this guy](http://www.r-bloggers.com/why-i-dont-like-jupyter-fka-ipython-notebook/) who misses the point I think) really dislike notebooks, but they are really good for what they are good at - sharing code ideas plus neat notes and stuff in dev, teaching interactively, even chaining languages together in a polyglot style. And doing all of this on github works really well (as long as you remember to always clear your output before checking in - version control can get a bit crazy otherwise)." 286 | ] 287 | }, 288 | { 289 | "cell_type": "markdown", 290 | "metadata": {}, 291 | "source": [ 292 | "## Some additional features\n", 293 | "* tab completion\n", 294 | "* function introspection\n", 295 | "* help" 296 | ] 297 | }, 298 | { 299 | "cell_type": "code", 300 | "execution_count": null, 301 | "metadata": { 302 | "collapsed": false 303 | }, 304 | "outputs": [], 305 | "source": [ 306 | "# first, let's install some packages to play with\n", 307 | "# replace lib string with your local library path\n", 308 | "install.packages(c(\"ggplot2\"),\n", 309 | " repos = \"http://cloud.r-project.org\",\n", 310 | " lib = \"C:/Users/michhar/Documents/R/win-library/3.2\")" 311 | ] 312 | }, 313 | { 314 | "cell_type": "code", 315 | "execution_count": null, 316 | "metadata": { 317 | "collapsed": true 318 | }, 319 | "outputs": [], 320 | "source": [ 321 | "# tab completion and introspection\n", 322 | "\n", 323 | "ggplot2::q # hit tab at end\n", 324 | "plot() # place cursor in () and tab" 325 | ] 326 | }, 327 | { 328 | "cell_type": "code", 329 | "execution_count": null, 330 | "metadata": { 331 | "collapsed": false 332 | }, 333 | "outputs": [], 334 | "source": [ 335 | "# help!\n", 336 | "library(rjson)\n", 337 | "\n", 338 | "?fromJSON" 339 | ] 340 | }, 341 | { 342 | "cell_type": "code", 343 | "execution_count": null, 344 | "metadata": { 345 | "collapsed": false 346 | }, 347 | "outputs": [], 348 | "source": [ 349 | "# My feeble attempt at debugging - your mission if you choose to accept it is to figure this out\n", 350 | "#library(htmlwidgets)\n", 351 | "#fname = 'tmp.html'\n", 352 | "\n", 353 | "options(error = browser())\n", 354 | "\n", 355 | "f <- function(a) g(a)\n", 356 | "g <- function(b) h(b)\n", 357 | "h <- function(c) i(c)\n", 358 | "i <- function(d) \"a\" + d\n", 359 | "f(10)\n", 360 | "t <- traceback()\n", 361 | "\n", 362 | "#saveWidget(t, file = fname, selfcontained = F)\n", 363 | "#IRdisplay::display_html(paste(\"