diff --git a/module2/ressources/jupyter.org b/module2/ressources/jupyter.org index c6b17146248d58f66a3a326f8d12bf798df867a6..612669636085efc70660fa93f8b1cc86222c4da2 100644 --- a/module2/ressources/jupyter.org +++ b/module2/ressources/jupyter.org @@ -6,7 +6,7 @@ #+OPTIONS: num:nil toc:t #+PROPERTY: header-args :eval never-export -* 1. Tips and tricks +* 1. Jupyter Tips and tricks The following [[https://www.dataquest.io/blog/jupyter-notebook-tips-tricks-shortcuts/][webpage]] lists several Jupyter tricks (in particular, it illustrates many =Ipython magic= commands) that should improve your efficiency (note that this blog post is about two years old so some of @@ -29,29 +29,75 @@ now). %%R -i df plot(df) #+end_src -Note that this =%%R= notation allows you to use R for the whole cell but +Note that this =%%R= notation indicates that R should be used for the whole cell but an other possibility is to use =%R= to have a single line of R within a python cell. +** Other languages +For any reason, you may be unsatisfied with the use of R or of +Python. Many other languages are available: +[[https://github.com/jupyter/jupyter/wiki/Jupyter-kernels][https://github.com/jupyter/jupyter/wiki/Jupyter-kernels]], including +non-free languages like SAS, Mathematica, Matlab... + +None of these other languages have been deployed in the context of our +MOOC but you may want to read the next sections to know more about how +to set up your own Jupyter notebooks on your computer and benefit from these +extensions. +* 2. Installing and configuring Jupyter on your computer +In this Section, we provide information on how to set up on your own +computer a Jupyter environment similar to the one deployed for this +MOOC. + +Note that Jupyter notebooks are only a small part of the picture and +that Jupyter is now part of a bigger project: [[https://blog.jupyter.org/jupyterlab-is-ready-for-users-5a6f039b8906][JupyterLab]], which allows +you to mix various components (including notebooks) in your +browser. In the context of this MOOC, our time frame was too short to +benefit from JupyterLab which was still under active development but +this is probably the best option now if you want to benefit from +cutting-edge Jupyter notebooks. + +** 2.1 Installing Jupyter +Follow these instructions if you wish to have a Jupyter environment on +your own computer similar to the one we set up for this MOOC. -* 2. Installing and configuring Jupyter on your machine -** 2.1 Existing install of Jupyter +First, download and install the [[https://conda.io/miniconda.html][latest version of Miniconda]]. We use +Miniconda version =4.5.4= and Python version =3.6= on our server. + +Miniconda is a light version of Anaconda, which includes Python, the Jupyter Notebook, and other commonly used packages for scientific computing and data science. + +Then download the [[https://gist.github.com/brospars/4671d9013f0d99e1c961482dab533c57][mooc_rr environment file]] and create the environment using conda: +#+begin_src shell :results output :exports both +conda env create -f environment.yml + +# Windows activate the environment +activate mooc_rr + +# Linux and MacOS activate the environment +source activate mooc_rr + +# Linux, MacOS and Windows: launch the notebook +jupyter notebook +#+end_src +** 2.2 Making sure Jupyter allows you to use R +The previous environment should ship with R but if you proceeded +otherwise and only have python available in Jupyter, you may want to +read the following section. *** • Installing [[https://github.com/IRkernel/IRkernel][IRKernel]] (R package) Do the following in R console: -Install =devtools= package: +Install the =devtools= package: #+begin_src R :results output :session *R* :exports both install.packages('devtools',dep=TRUE) #+end_src -Define proxy if needed: +Define a proxy if needed: #+begin_src R :results output :session *R* :exports both library(httr) set_config(use_proxy(url="proxy", port=80, username="username", password="password")) #+end_src -Install =IRkernel= package: +Install the =IRkernel= package: #+begin_src R :results output :session *R* :exports both devtools::install_github('IRkernel/IRkernel') @@ -59,6 +105,7 @@ IRkernel::installspec() # to register the kernel in the current R installation #+end_src *** • Installing rpy2 (Python package) +On Linux, the rpy2 package is available in standard distributions #+begin_src shell :results output :exports both sudo apt-get install python3-rpy2 python3-tzlocal #+end_src @@ -81,33 +128,10 @@ Install also =tzlocal=: #+begin_src shell :results output :exports both python -m pip install tzlocal #+end_src - -** 2.2 New install of Jupyter -Follow these instructions if you wish to have a Jupyter environment on -your own machine similar to the one we set up for this MOOC. - -First, download and install the [[https://conda.io/miniconda.html][latest version of Miniconda]]. We use -Miniconda version =4.5.4= and Python version =3.6= on our server. - -Miniconda is a light version of Anaconda, which includes Python, the Jupyter Notebook, and other commonly used packages for scientific computing and data science. - -Then download the [[https://gist.github.com/brospars/4671d9013f0d99e1c961482dab533c57][mooc_rr environment file]] and create the environment using conda: -#+begin_src shell :results output :exports both -conda env create -f environment.yml - -# Windows activate the environment -activate mooc_rr - -# Linux and MacOS activate the environment -source activate mooc_rr - -jupyter notebook -#+end_src - ** 2.3 Additional tips *** • Exporting a notebook -Here is what we had to install on our recent debian machine to make sure -the notebook export via latex works: +Here is what we had to install on our recent debian computer to make sure +the notebook export via LaTeX works: #+begin_src shell :results output :exports both sudo apt-get install texlive-xetex wkhtmltopdf #+end_src @@ -135,14 +159,6 @@ by choosing the right operating system. You will be prompted to install some spe packages when exporting to pdf. *** • Side note about Jupyter, JupyterLab, JupyterHub... -Note that Jupyter notebooks are only a small part of the picture and -that Jupyter is now part of a bigger project: [[https://blog.jupyter.org/jupyterlab-is-ready-for-users-5a6f039b8906][JupyterLab]], which allows -you to mix various components (including notebooks) in your -browser. In the context of this MOOC, our time frame was too short to -benefit from JupyterLab which was still under active development but -this is probably the best option now if you want to benefit from -cutting-edge Jupyter notebooks. - *** • Improving notebook readability Here are a few extensions that can ease your life: - [[https://stackoverflow.com/questions/33159518/collapse-cell-in-jupyter-notebook][Code folding]] to improve readability when browsing the notebook.