******************
Navigator Tutorial
******************

.. contents:: Here are some of the things you can do with Anaconda Navigator.
   :local:

Why use Navigator?
------------------

Many scientific packages require specific versions of programs in order to run.
These other programs are called *dependencies*. The Conda Package Management
System, and now Anaconda Navigator, allow you to create isolated
*environments* so the programs will not interfere with other programs you
have created, and you can install the exact programs needed.

Anaconda Navigator is an easy, point-and-click way to use packages and
environments so you don't have to use Conda commands in a terminal window. You
can use it to find the packages you want, install them in an environment, and
run the packages and update them, all inside Navigator.

.. _navigator-basic-workflow:

Navigator basic workflow
------------------------

* Create and activate a new environment for the package you want to use.

* Search for and install the package you want.

* Open and use the package.

We'll go over each of these steps in detail below.

Step 1: Create and activate a new environment for the package you want to use.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Let's say your professor told you to get BioPython, a popular library for
biologists. A quick Google search lets you know that like most packages written
in Python, it's available for Windows, OS X and Linux, 32-bit and 64-bit, and
all versions of Python back to 2.6. We'll create an environment using the
newest version of Python, 3.5.

**NOTE:** Why choose Python 3.5? It's the latest and recommended version of
Python to use.

In Anaconda Navigator, go to the Environments side tab, then click the bottom
*Create* Button. The "Create new environment" dialog box appears:

.. image:: img/navigator-tutorial01.png

Give your environment a memorable name, here we called ours "biopy", select
Python 3.5, and click the *OK* Button. Navigator creates the new environment
and activates (switches to) it, as shown by the highlighted green bar:

.. image:: img/navigator-tutorial02.png

**NOTE:** All actions take place in the active environment, shown by the
highlighted green bar. In the above image the "biopy" environment is active.

.. _install-package:

Step 2: Search for and install the package you want.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Select *ALL* to search for all possible packages, then type the name of the
package you want in the search box. In the search results list, put a check
next to the package you want to install:

.. image:: img/nav-tutorial03.png

From the drop-down menu that appears, select *Mark for installation*:

.. image:: img/nav-tutorial04.png

To begin installing, click the *APPLY* Button on the bottom right:

.. image:: img/nav-tutorial04b.png

When it asks you if you want to proceed, click the *OK* Button.

Anaconda Navigator gets all the dependent files you need and installs them in
your new environment.

.. _open-package:

Step 3: Open and use the package.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

On your "biopy" environment name which is still highlighted (if not, click to
highlight it), click the arrow to bring up the menu of choices to open your
package:

.. image:: img/navigator-tutorial05.png

Here we have selected *Open Terminal*. A terminal window will appear, type
jupyter-notebook to open Jupyter Notebook in a new browser window or tab.

To exit Jupyter Notebook, after closing the notebook tabs or windows in the
browser, press *Ctrl + C* and answer "Y" [for "yes"] to stop the notebook in
the terminal, then type exit and press "Enter" to exit the terminal.

Tutorial #1: Display BioPython's help text in a Jupyter Notebook.
-----------------------------------------------------------------

You've already installed and opened BioPython above. To verify that the
installation is working, Open a Jupyter Netbook, chose *New -> Python 3* (you
may have a different Python version depending on your installation).

.. image:: img/navigator-tutorial08.png

Now paste the following code into the first cell:

::

  import Bio
  help(Bio)

To run the code, click *Cell -> Run* Cells from the menu bar or use the
keyboard shortcut *Ctrl + Enter*. This shows the help information for the
biopython package.

Tutorial #2: Use QGrid with Yahoo S&P 500 data
----------------------------------------------

QGrid is a dataframe viewer for Jupyter notebook. To test your installation,
use QGrid to display S&P 500 stock market data.

To install QGrid and Pandas Datareader follow the instructions on
:ref:`how to install a package <install-package>`, but install "qgrid" and
"pandas-datareader" instead of "biopython".

:ref:`Open a Jupyter Notebook <open-package>` and paste the
following code into the first cell:

::
  
  import qgrid
  import pandas as pd
  import pandas_datareader
  pd.set_option('display.max_rows', 8) # Prevents the grid from being too large 
  from pandas_datareader.data import get_data_yahoo
  spy = get_data_yahoo(symbols='SPY', start=pd.Timestamp('2011-01-01'), 
                       end=pd.Timestamp('2014-01-01'), adjust_price=True) 
  spy

To run the code click *Cell -> Run Cells* from the menu bar or use the keyboard
shortcut *Ctrl + Enter*.

This gets a pandas DataFrame containing the daily prices for the S&P 500 from
1/1/2011 - 1/1/2014 and displays the first and last four rows of the DataFrame.

.. image:: img/navigator-tutorial06.png

Thanks to https://github.com/quantopian/qgrid and
http://nbviewer.jupyter.org/gist/TimShawver/b4bc80d1128407c56c9aifor example
code.

Tutorial #3: Use R computer language in a Jupyter Notebook
----------------------------------------------------------

It is possible to use R, the popular programing language for statistics, in a
Jupyter Notebook. To do so, we'll follow the exact
:ref:`navigator-basic-workflow` shown above. 

1. Create and activate a new environment for the package you want to use. 
Go to the Environments tab, click the "Create" button at the bottom left, 
give your new environment a descriptive name like "R essentials" and check the 
"R" box for the R computer language to be installed. Click the "Create" button 
again to begin creating your new environment. After it has finished 
installing, highlight your new environment name to activate it.

2. Search for and install the packages you want. You want both R language and R 
essentials, which are available in the channel named MRO. Show uninstalled 
packages by selecting "All" from the drop-down menu. Then add the MRO channel to 
your channel list by clicking "Channels", clicking "Add", selecting the white 
box that appears and typing "mro" and the enter key, and clicking "Update 
channels". Now in the search box when you type "r" or "r-es" the package name 
"r-essentials" appears in your search results. Check the box and from the 
drop-down menu that appears, select "Mark for installation". Repeat for the "r" 
package and any other packages you wish to install. Click the Apply button that 
appears at the bottom right. A dialog box appears asking you to confirm, so 
click the "Ok" button to install R language and R Essentials.

3. Open and use the new R language package. From the Environments tab, open 
Jupyter Notebook by highlighting your new environment name, clicking the Open 
icon and selecting "Open with Jupyter Notebook."  To create a new notebook 
with the R language, on the Jupyter Notebook top menu, choose *New -> R*. 
Paste the following code into the first cell::

  library(dplyr) 
  iris

Click *Cell -> Run Cells* from the menu bar or press *Ctrl + Enter*. This will
show the iris data table.

To plot the data, click *+* to open a second cell, then paste the following
code into the cell::

  library(ggplot2) 
  ggplot(data=iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species)) + geom_point(size=3)

Again, click *Cell -> Run Cells* from the menu bar or press *Ctrl + Enter*

.. image:: img/navigator-tutorial07.png

For more information and to see the example code, see the `Continuum Developer
Blog <https://www.continuum.io/blog/developer/jupyter-and-conda-r>`_.
