not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

325 lines
15 KiB

  1. \documentclass[pdftex,12pt]{artikel3}
  2. % Compile with: pdflatex
  3. % Settings for source listings.
  4. \usepackage[dvips,letterpaper,margin=1.1in]{geometry}
  5. \usepackage{listings,graphicx}
  6. \usepackage{url} % usage \href{}{}
  7. \usepackage{xcolor}
  8. %% \usepackage{soul}
  9. %% \usepackage{lipsum}
  10. \usepackage{mathtools}
  11. % \newcommand{\myul}[2][black]{\setulcolor{#1}\ul{#2}\setulcolor{black}}
  12. \usepackage{array}
  13. %% \usepackage{multirow}
  14. \usepackage{alltt}
  15. \usepackage{pifont}
  16. \usepackage{courier}
  17. \usepackage{fancyvrb}
  18. \usepackage{enumitem}
  19. \usepackage[hidelinks]{hyperref} % hide links in hyperref text
  20. \usepackage{cleveref} % nice table/figure refs. put after hyperref
  21. % sample stuff for tables and figs
  22. %\usepackage{blindtext}
  23. \usepackage{makeidx} % for makeindex
  24. \usepackage{tocloft} % for nicely formatted toc, tof, lof
  25. \usepackage{booktabs,longtable,tabu}
  26. \usepackage[utf8]{inputenc}
  27. \usepackage[T1]{fontenc}
  28. \usepackage{imakeidx}
  29. %% preamble
  30. % the tabfigref command outputs a table or figure reference
  31. % with pattern: "Figure N, The Caption," or "Table N, The Caption,"
  32. % Note: output has a trailing comma(,) for phrasing.
  33. \newcommand{\tabfigref}[1]{\autoref{#1}, \nameref{#1},}
  34. \setcounter{tocdepth}{3}
  35. \makeindex[columns=2, title=Alphabetical Index, intoc]
  36. \lstset{tabsize=4,language=Python,showstringspaces=false}
  37. \title{
  38. \begin{center}
  39. \huge{Jupyter Notebook User Document} \\
  40. \huge{CSCI-471-02}\\
  41. \end{center}
  42. \\
  43. \\
  44. \\
  45. \\
  46. \\
  47. \author{} % \author{Jeffery B. Russell} \\
  48. % \author{Dan Moore}
  49. \date{} % \date{Febuary 20, 2020}
  50. }
  51. %% document starts
  52. \begin{document}
  53. \maketitle
  54. \begin{center}
  55. \author{Jeffery B. Russell},
  56. \author{Daniel Moore},
  57. \author{Louden Yandow}
  58. \date{Febuary 20, 2020}
  59. \end{center}
  60. \newpage
  61. \tableofcontents
  62. \addtocontents{toc}{~\hfill\textbf{Page}\par}
  63. \addcontentsline{toc}{section}{\listfigurename} % include lists of figs
  64. \newpage
  65. \listoffigures
  66. \addtocontents{lof}{~\hfill\textbf{Page}\par}
  67. \newpage
  68. \section{Introduction}
  69. Jupyter \index{jupyter} is an open-source web-based notebook tool that you can use as your development environment.
  70. A coding notebook enables you to intermix markdown and code blocks that you can execute in a single document. This is heavily used in the education and research fields because it makes writing reports easy and reproducible. With Jupyter you can create content that has live code, equations, visualizations and explanatory text.
  71. Jupyter Lab extends the basic notebook functionality and provides you a full web environment to work in. Using this interface you can open terminals, manage files, and even tile multiple editors.
  72. Applications of Jupyter Jab:
  73. \begin{itemize}
  74. \item Quick experimentation
  75. \item Telling a story with data
  76. \item Writing a report
  77. \item Sharing code snippets for education
  78. \end{itemize}
  79. In this document we are going to go over the basic installation and usage of Jupyter Lab for personal use developing python\index{python}. In the advanced usage section we go over how to use Jupyter on a remote server. This is particularly useful when you want to run algorithms on a remote computer.
  80. \section{Installation}
  81. To install, first go to \href{https://jupyterlab.readthedocs.io/en/stable/getting_started/installation.html}{Jupyter Install}\footnote{\url{ https://jupyterlab.readthedocs.io/en/stable/getting_started/installation.html}} for a detailed guide. This user document assumes that you install Jupyter Lab. \textbf{Do Not Only Install Jupyter Notebook. }
  82. \subsection{Prerequisites}
  83. In order to install Jupyter, you must have Python installed. Your version of Python \textbf{must be 3.3 or greater}. As part of having Python, you will also have pip. Click \href{https://www.python.org/downloads/}{here}\footnote{\url{ https://www.python.org/downloads/}} for the latest version of Python.
  84. However, we highly recommend you take the time now to install \href{https://docs.conda.io/projects/conda/en/latest/user-guide/install/}{Conda}\index{anaconda} now because it'll be helpful later one with some of the more advanced features of Jupyter as well as machine learning focused Python.
  85. You should also have either Firefox, Chrome or Safari as these are the only browsers Jupyter\index{jupyter} is currently known to work with.
  86. \subsection{Installation on Linux}
  87. There a two ways of installing Jupyter on Linux.\\
  88. \\
  89. Using pip\index{pip} the command is \textbf{pip install jupyterlab}.\\
  90. \\
  91. Using conda the command is \textbf{conda install -c conda-forge jupyterlab}
  92. \subsection{Installation on Windows}
  93. Installation on Windows is the same as installation on Linux except that you must also add the user-level bin directory if you installed using \textbf{pip install --user}.
  94. \section{Usage}
  95. To run Jupyter Lab, open your computer's command terminal and enter the following command. This will open Jupyter Lab in your default web browser.
  96. \texttt{jupyter lab}
  97. \tabfigref{fig:jupyterlablauncher} is what you will see upon first running Jupyter Lab. Otherwise, it can open to the most recent notebook you were working on.
  98. \begin{figure}[h!]
  99. \centering
  100. \includegraphics[width=65mm]{launcher.png}
  101. \caption{Default Jupyter Lab launcher}
  102. \label{fig:jupyterlablauncher}
  103. \end{figure}
  104. \subsection{Navigation}
  105. Once Jupyter Lab is running, you will see on the left side of the screen a column of icons. Each icon will open a different panel to the right of it when you click it. From top to bottom, these icons have the following functions:
  106. \begin{itemize}
  107. \item File Browser (folder icon): displays a file browser for the user to open, move, or delete their files.
  108. \item Running Terminals and Kernels (square stop button inside a circle): shows the user all currently active terminal and kernel sessions.
  109. \item Commands (palette icon): allows the user to enter various commands into Jupyter Lab.
  110. \item Notebook Tools (wrench icon): shows various options for the user's current notebook.
  111. \item Open Tabs (a tabbed window icon): lists all currently open tabs in Jupyter Lab.
  112. \end{itemize}
  113. Additionally, the top toolbar contains the following different drop-down menus: File, Edit, View, Run, Kernel, Tabs, Settings, and Help.
  114. \subsection{Creating a Notebook}
  115. To create a notebook (the working document for both python code and text markdown) from the launcher (\tabfigref{fig:jupyterlablauncher}), click on the Python 3 icon under the orange notebook symbol. Alternatively, if you don't have the launcher open, you can click on File in the toolbar, click New, and finally click Notebook.
  116. This will open an empty, untitled notebook. If you right click on the tab above, or on the name of your notebook in the "Open Tabs" panel on the left, you can rename your notebook.
  117. \subsection{Running a Notebook}
  118. With a notebook open, you can start writing in the editor, the big empty area on the right half of the screen. Just above the editor, you will find the icon to save the open notebook.
  119. There are also a number of icons that directly relate to the "cells" you are writing in. A cell is either python code, markdown, or raw text. You can change what type of text a cell is by clocking on the drop-down menu just above the editor that will say either "Code", "Markdown", or "Raw".
  120. Notebooks work through these cells, in order from top to bottom. The icons above the editor, from left to right, do the following:
  121. \begin{itemize}
  122. \item add a cell after the currently selected cell.
  123. \item cut the currently selected cells.
  124. \item copy the selected cells.
  125. \item paste the cells from the clipboard.
  126. \item run the selected cells and advance to the next cell.
  127. \item interrupt the kernel.
  128. \item and restart the kernel.
  129. \end{itemize}
  130. The following example shows how to write code, run code, and insert raw text into the notebook. First, write some python code and click the "Run selected cells and advance" button (circled in red in the figure below). Our output is shown in the next figure (output is given its own unique cell immediately after the cell that produced it).
  131. \begin{figure}[h!]
  132. \centering
  133. \includegraphics[width=15cm]{code_before_running.png}
  134. \caption{Code before being run}
  135. \label{fig:codebeforerunning}
  136. \end{figure}
  137. \begin{figure}[h!]
  138. \centering
  139. \includegraphics[width=15cm]{code_after_running.png}
  140. \caption{Code after being run}
  141. \label{fig:codeafterrunning}
  142. \end{figure}
  143. You can also insert raw text into your document, as shown below. To do this, change the drop-down menu from Code (or Markdown) to Raw, and type what you want in the cell.
  144. \begin{figure}[h!]
  145. \centering
  146. \includegraphics[width=15cm]{raw_text_example.png}
  147. \caption{Example of raw text}
  148. \label{fig:rawtextexample}
  149. \end{figure}
  150. \subsection{Exporting Notebooks}
  151. In order to export the document, click the \textbf{File} tab, mouse down to \textbf{Export Notebook As...} and then click any of the myriad of formats to export as that format. The most popular export formats are PDF, Markdown \index{markdown}, and HTML.
  152. \subsection{Customization}
  153. Customization of Jupyter is in general exceptionally easy.\\
  154. \\
  155. In order to change the theme, one simply needs to go to the \textbf{Settings} tab and drop down to JupyterLab Theme. This will allow you to change from light to dark mode as well as the font sizes for the code, content and UI.\\
  156. \\
  157. Scrolling down the rest of the Settings you see many other things that can be customized.\\
  158. \\
  159. Advanced settings allows you to customize many aspects of Jupyter Lab such as keyboard shortcuts, terminal settings, and a myriad of others. \tabfigref{fig:configuration} shows the configuration menu for Jupyter Lab.
  160. \begin{figure}[h!]
  161. \centering
  162. \includegraphics[width=15cm]{settings.jpg}
  163. \caption{Code after being run}
  164. \label{fig:configuration}
  165. \end{figure}
  166. \section{Advanced Usage}
  167. In this section we are going to go over how to use multiple programming languages in Jupyter\index{jupyter} and how to connect to your Jupyter Lab instance remotely.
  168. \subsection{Multiple Kernels}
  169. Adding a Kernel in Jupyter enables you to program with another programming language like R\index{r} or Scala\index{scala}.
  170. Up to this point we have been working with the python kernel\index{python} which enables you to make python notebooks. The ability to use multiple kernels is useful for education and having cohesion within one IDE\index{IDE}.
  171. You can view a complete list of kernels here:
  172. \href{https://github.com/jupyter/jupyter/wiki/Jupyter-kernels}{https://github.com/jupyter/jupyter/wiki/Jupyter-kernels}
  173. \begin{figure}[h!]
  174. \centering
  175. \includegraphics[width=50mm]{exampleKernels.PNG}
  176. \caption{Example of multiple kernels}
  177. \label{fig:multKernels}
  178. \end{figure}
  179. \tabfigref{fig:jupyter_server} shows an example of what your launcher would look like with multiple kernels installed.
  180. The most common way to install a kernel is by using the Anaconda\index{anaconda} prompt, pip\index{pip} support is limited here.
  181. Once you start adding multiple kernels, it is best if you start running Jupyter Lab through docker\index{docker} because it would make porting it to another computer easier. A popular docker jupyter lab instance with Scala, Python, and R can be found here:
  182. \href{https://hub.docker.com/u/jupyter/}{https://hub.docker.com/u/jupyter/}
  183. \subsection{Remote Connection}
  184. If you have a firewall Jupyter Lab will only be available on your
  185. local machine at "localhost:8888", however, it is possible to connect to Jupyter Lab from remote computers.
  186. This is helpful because you can connect to the same Jupyter instance from multiple computers. This would also save you resources on your local computer so you can program on a lightweight chrome-book that would not be able to run a full IDE\index{IDE} like Pycharm\index{pycharm}.
  187. The first step to enable remote host would be to set a password that you can connect to the notebook using. You can set a password that you use to log into the website using the following command:
  188. \texttt{jupyter notebook password}
  189. The Second step would be to launch the Jupyter Lab instance in a headless environment -- it never launches a web browser.
  190. \texttt{jupyter lab --no-browser --port=6000}
  191. The final step is to connect to the Jupyter Lab instance from your
  192. remote computer. The easiest way to do this is via a local port
  193. forward in SSH\index{ssh}. This command essentially forwards all of the traffic on your local machine on a specific port to a remote computer over a ssh connection. The main benefit of doing this is that all the traffic over the connection is encrypted.
  194. \tabfigref{fig:jupyter_server} shows an overview of what the network architecture looks like.
  195. \texttt{ssh -L 6000:localhost:6000 user@remote-host}
  196. \begin{figure}[h!]
  197. \centering
  198. \includegraphics[width=15cm]{remoteJupyter.png}
  199. \caption{Network Overview}
  200. \label{fig:jupyter_server}
  201. \end{figure}
  202. After you execute the command above on your remote computer you
  203. would be able to access your Jupyter Lab instance on your computer's "localhost:6000".
  204. \newpage
  205. \section{Glossary}
  206. \begin{itemize}[label={}]
  207. \item {\bf Anaconda}: Anaconda is a package manager for the R and Python languages aimed towards data science" \footnote{\url{ https://www.anaconda.com}}.\index{anaconda}\\
  208. \item {\bf IDE}: Interactive Development Environment.\index{IDE}\\
  209. \item {\bf Jupyter}: Nonprofit organization created to "develop open-source software, open-standards, and services for interactive computing across dozens of programming languages" \footnote{\url{ https://jupyter.org/}}.\index{jupyter}\\
  210. \item {\bf Markdown(MD)}: Lightweight markup-language \footnote{\url{https://en.wikipedia.org/wiki/Markdown}}.\index{markdown}\\
  211. \item {\bf pip}: Tool for installing and managing python packages \footnote{\url{ https://pypi.org/project/pip/}}.\index{pip}\\
  212. \item {\bf Pycharm}: A popular versitile python IDE developed by \href{https://www.jetbrains.com/}{Jetbrains}.\index{IDE}\\
  213. \item {\bf Python}: High-level interpreted, general purpose programming language \footnote{\url{ https://www.python.org/}}.\index{python}\\
  214. \item {\bf R}: Programming language for statistical computing and graphics \footnote{\url{ https://www.r-project.org/}}.\index{r}\\
  215. \item {\bf Scala}: General purpose functional programming language that runs on the JVM \footnote{\url{ https://scala-lang.org/}}.\index{scala}\\
  216. \item {\bf ssh}: Secure Socket Shell -- used in connecting to a remote computer over a encrypted channel.\index{ssh}\\
  217. \end{itemize}
  218. \newpage
  219. \section{References}
  220. \begin{enumerate}
  221. \item
  222. \url{https://jupyter.org/}
  223. \item
  224. \url{https://www.python.org/}
  225. \item
  226. \url{https://en.wikipedia.org/wiki/Markdown}
  227. \item
  228. \url{https://pypi.org/project/pip/}
  229. \item
  230. \url{https://scala-lang.org/}
  231. \item
  232. \url{https://www.r-project.org/}
  233. \item
  234. \url{https://www.jetbrains.com/}
  235. \end{enumerate}
  236. \newpage
  237. %\section{Index}
  238. \printindex
  239. % outputs its own heading, which does not match the sections
  240. \end{document}