 There are certainly many environments available today that we can use to write our Julia code in. In this video I want to talk to you about the Pluto notebooks. We're all familiar with Jupiter notebooks. Pluto notebooks are a bit different. There's the plot Pluto.jl package that we're going to use. We're going to install it and we're going to use it to write some code. So I can show you what a Pluto notebook is all about. So just a word or two on Julia environments. Remember to keep separate and distinct environments for each of your Julia projects. You should not install packages just inside of your base Julia installation. One or two, for instance, I do install Pluto in the base environment but there's only a handful of packages that are installed there. We create a folder or a directory depending on whether you're in the Mac world or in the Windows world. We create a folder and inside of that folder we will create our notebooks and we're going to install the packages or at least the references to the packages specific to that project. So every time I start a new project I reinstall the packages that are specific to that project that I'm working on. And what you do there, you don't have this, I'm going to use the word cross-contamination but this problem of dependencies and versions, they don't really talk to each other. So we're just going to maintain an environment and packages only in that environment and it all happens in a single folder. So really keep your projects in its own folder and we're going to generate an environment just using Julia's package manager, PKG. So what is this folder structure? I'm just going to use the word folder instead of directory. What does your folder look like on your hard drive? Well this is a Mac, so on my side I'm going to have users, and that's the directory or the folder structure on my hard drive. Then JUAN, that's just my username. And then in my documents folder I have a sub-folder called Julia. And in that Julia folder will be all my projects and every project has a name and as you can see there I just use some placeholder text environment underscore name. So I'm going to have a bunch of those sub-folders in this folder structure. And in that environment underscore name, whatever it's called, we're going to use Pluto demo for this video. You're going to find two files after you've generated this environment using Julia's package manager. You're going to find the project.toml file and a source folder SRC. And it's automatically going to generate a single file.jl file in that SRC folder for you. After you've activated this environment, I'm going to show you how to do this, and you install your first package, you're also going to have a manifest.toml file. And you can read up on the package manager on Julia's website about the project.toml file and the manifest.toml file, what is kept in there to keep the versions or information about your project is kept in those files. And as we see at the bottom there, once you've generated this environment, you're also going to have whatever you called that environment, it's also going to have an environment underscore name. So that specific name of the environment.jl file for you ready to use. So what does the code look like? First of all, you just have to open a terminal or command prompt, and you've got to navigate to where you have all your projects. So in my instance, as you've seen before, it uses my name, forward slash documents, forward slash Julia. And then we're going to type in Julia. Now I'm presuming that Julia is in part of your path or your environment variable so that when you do type in Julia, your computer knows where to go, get the Julia executable. So Julia and then dash e, and then inside of single quotation marks, using PKG, we're just going to use the package manager, and then semicolon, then package.generate, and then the name of this environment, the project that you're working on. So in our instance, we're going to call a Pluto demo. And when we're done, you'll see inside of my Julia folder there, there'll be a Pluto demo folder. And then we're going to just change into that directory. So on terminal, no matter what terminal you use, usually cd, you're going to cd into the change directory, into this folder, into the Pluto demo folder, and then we're going to type Julia dash dash project equals full stop. That's going to activate this environment. So you're no longer working in your base Julia installation, you're now working in this newly generated environment, Julia environment. And then once we start Julia and we go into the repl, we're going to use using PKG and then PKG.add. And for instance, there's a package Vega lite that we're going to use. And then comma, you see preserve equals preserve direct. Now there's a couple of those keywords, the values at least for the keyword preserve, and preserve direct just means that the version that you're going to install now it's going to stick to that version. So it becomes very important when you do package development, for instance, that you really take control over the versions of different dependencies that you do have. But for simple projects like this, I just use preserve direct and it's always going to keep that version of the package that we started with. Now as I mentioned, I do install Pluto in my base Julia installation. I start the repl again, but just in my base Julia installation and we're going to install Pluto, but then use the code import Pluto and then Pluto dot run. Remember if we use import, we've got to reference that namespace. So it's Pluto dot run. So you have to get to the run function. You have to use the Pluto, the word itself there, Pluto dot run. And then we're going to use a port address and you can use available ports on your computer. That's the example at least on Pluto's website. Remember just a few things. I do not save my files, my working notebooks in the SRC sub folder. I just save it in the first structure. In other words, in the project names folder and where the project dot to ml file and manifest dot to ml files are. And then I'm going to show you how to activate the environment in the notebook because even though you try to activate it outside of, you've got to activate it in the notebook and I'm just going to show you how to use markdown in Pluto because that is different from a Jupyter notebook and also just showcase the interactive, the interactivity of the Pluto notebook environment. So my desktop here, we've opened a terminal and I'm just changing directory. As you can see, they're changing directory into my documents, so that's where I want to be because that is where I have my list of folders that contain all my projects. So as mentioned, I'm going to type Julia and then dash E, open a single quotation mark. We're going to say using PKG. So this would be the same as typing code in the REPL, semi colon and then PKG dot generate. Generate. And then parentheses and a quotation mark and this is where we're going to write the name of our project. So in my instance, I'm going to call a Pluto demo. Of course you give the name that is appropriate to the type of project that you are working on. So I'm going to close my quotation marks, close the parentheses and then close the single quotation mark there. So let's just go back all the way there and just correct that spelling error there and then all the way to the end, let's run this. And there we can see generating project Pluto demo and we'll see inside of that folder, we now have a project.toml file. We'll also have an SRC folder and inside of that SRC folder is a Pluto demo.jl. So it's the same name as our project name and .jl. So that's just a normal Julia file that you can open up using your IDE. It will not open in Pluto though, although Pluto is saved as, Pluto notebooks are saved as .jl files, but that is not a Pluto notebook so that's not going to work for us. So now we're just going to change directory into this folder that was generated using the pkg.generate function and now we can see we're there and if I type ls or if you're in the window you're going to type dir, you see the project.toml file and then an SRC that is going to be a folder inside of there but there's our project.toml file. Now we want to activate this environment so I'm going to say Julia once again and then dash dash project equals full stop or period and if I do that we see Julia has started and it is 1.5.1 at the time of this recording but if I hit the right square bracket to go into my package manager we see I'm not in Julia at v1.5 I'm in the Pluto demo environment. So anything that I install here will only be for this environment. It will not be available to any of the other environments or to my base Julia installation. So here I'm going to say using pkg and then we can just start adding one or two packages so pkg.add Now you can do this in the package manager itself by the right square bracket but I preferred here so that we can showcase this to preserve keyword. So let's do vagalite as we promised so vagalite close my quotation marks, preserve equals and then all in uppercase preserve underscore direct as simple as that preserve direct and there we go it's now going to install vagalite for us and there we go let's install something else as well let's just install data frames the data frames package there we go done so if I hit my right square bracket now to get into the package manager I just type st we see that we have data frames and vagalite installed and we can see the versions there which is going to install the newest versions we didn't specify the version that we wanted but that is there now specifically to this environment so let's just exit from Julia here now and if I type ls you'll see there's a manifest.toml file now as well it contains the information about these packages that I have installed so what I'm going to do I'm just going to quit the terminal and just restart it we're back in the terminal and I'm just going to type Julia and that's just going to start in the base installation if I hit the right square bracket now you see I'm in version 1.5 so I haven't activated the specific environment and this is where I would add Pluto now I've already done so but I would just say add Pluto and as I say it's one of the handful of packages that I do put in my base Julia installation I've done that already so let's just say import Pluto and it gives us a little bit of information there and we're going to say Pluto.run the run function and for my port address I'm just going to say 1, 2, 3, 4 now it might give you a little bit of information that you have to copy and paste into your browser URL so that it would navigate to this generated notebook it's just going to happen automatically we see we're in localhost 1, 2, 3, 4 and we have a Pluto.jl notebook and you can see there's some sample notebooks that you can work through or we can generate a new notebook so let's just generate a new notebook and there we have it a brand new notebook live docs that gives you some information if you highlight some functions in Julia and look at the live docs it's going to give you information about that function there is a little bit of feedback that you can give and statistics about your notebook but first of all we're just going to save the notebook so I'm going to go up here and to save notebook and once you click on it you're going to be in your home folder automatically I want to go to documents and you see it finds documents there and then I'm going to go into Julia and then I'm going to go into Pluto demo and that is where I'm going to save this file so you can see I'm in the same folder as manifest.toml and the project.toml file I'm not going to go into SRC and save it there so let's just call this one demo as well so it's demo and you see the auto completion there.jl so I'm going to click that and I'm going to say choose and it wants to overwrite the default that it created and there we go and it's automatically saved but we're interested in writing some code so you see here we have one code cell and if I hover over it you see a plus above and a plus underneath let's increase the size of this so I can show you so the plus on top and a plus underneath and then also a little eyeball and that's going to hide our code now the code that you write the execution of that cell is above the cell so unlike a Jupyter notebook where it's below the cell it's going to be above so let's just start with some markdown now that's very simple you can't see any drop down menus here to change something into a markdown cell but you just type md and you can do a quotation mark I'm going to do a single pound sign or hash symbol and I'm going to say interactive interactive notebook that's going to be the name of this notebook or at least the mark down first level name of it and I'm going to hold down control and hit enter when I do that it's automatically going to create a new cell underneath if I just hit shift and enter it'll execute the cell but it won't open a new one you'll have to go onto that little plus signs above or below so I'm going to hold down control and hit return and it's going to do what we used to in a Jupyter notebook at least it's just going to print this interactive notebook as a header because I used a single hash tag that will be equivalent to an HTML now if I hit on this little eyeball it hides the code and now all I can see is obviously just the nice title of this page so let's make another one I'm going to say md and we're just going to have two and we're going to say our libraries that we're going to use or our packages libraries there we go let's execute that I've got two hashtags there or symbol pound signs and so that's going to be slightly smaller and once again I can just hide the text there so I didn't hit control and enter I hit shift and enter and you can see it didn't automatically create a new cell for me so let's just hit the plus there and that's it what we need to do now is just to use the package manager so I'm going to hold down control and return and that line is executed because what I want to do now is to activate the environment so activate now very importantly with this activate function parentheses and then our quotation mark because we have to tell it where our project.toml file is now I've already saved this demo file here in the Pluto demo folder and I know that that contains the project.toml file in the manifest.toml file so this notebook and those two files are in the same folder so I don't have to go and type the whole address on my hard drive my internal drive to get to to that project.toml file I can just type it in directly so it's project.toml close my quotation mark close my parentheses but remember please do this save first if you don't do that you have to type in the whole address to do that file so control and enter there we go and now this this environment is activated and remember the two packages that we had installed because we say pkg.status now that's not going to print out in this notebook I'm just going to hit down control and return but if I bring up my terminal window you'll see the status function being executed and there's my terminal and you can see things happening as we executed but this last two lines you see my data frames package and the Vega lite package there because we are inside of this specific environment we've activated this environment inside of Pluto and this Pluto notebook and you can see there projectPluto version 0.1.0 now remember we used the package manager actually to create packages or in this instance all we're going to use is just to showcase this notebook environment so as far as our libraries or packages are concerned let's just do Vega lite then using Vega lite control and and return and you can see the little bar run up and down there it's executing that cell so it's pre-compiling the package for us and I can keep on typing in the meantime we're also going to use the data frames package and then the last package we're going to use is one of the packages that is part of Julia we're just going to use the random package as well so let's create some data so let's make it mark down and keep things night and we say two two quotation marks let's have that two pound symbols I should say mark down and we're going to say we're just going to create our data and let's just hide that code so it looks nice so let's just create some random values I'm going to use a computer variable called VELS to hold this vector object and this array object and I'm going to say rand 1000 so it's just going to generate 1000 values for us there I'm going to put the semi-colon because I don't want that to be expressed to the screen so there we have 1000 values and let's create a data frame from these so df equals data frame and what we're going to have is let's call it var1 it's going to be the column name and I'm going to set that equal to VELS so we're going to have this single the single column in our data frame and it's going to contain those 1000 rows for each of those one cell or one row for each of those values here we can see the first five rows is going to be different from you because we did not seed the seed of random number generator and now let's just investigate this data so let's say let's say explore the data so this is going to be our section on exploring the data and let's create a new cell for ourselves at the bottom so let's just create a plot just the histogram of these 1000 values now in a Jupiter in a book in a Pluto notebook it is one line of code we can just execute one thing at a time if you want multiple things to be executed in one cell you've got a rapid in a begin end statement so I'm going to say begin and we're going to use we're going to pipe our data frame into a plot and we're going to use the macro at VEL plot and what we want is we want a bar plot we want the X to be and inside of curly braces X we're going to put a few things we're going to plot of our one is going to be on our X axis we're going to say bins equals two to create bins for us and then on the Y axis we just going to put counts so I do have a video out on the use of Vega light it's a fantastic fantastic plotting environment so have a look at that I'll put a link on in the description down below so we have a begin and end statements there that we wrap this what is essentially multi line so line of code there it looks like a single line of code but there's obviously quite a few things happening so let's have a look at that and there we go we see our histogram V neatly there now what I'm going to do I'm just going to make this a tad smaller so I'm going to go up here to VALS where I have that line of code and I'm going to re-execute it so we're going to generate a thousand new values and what I want you to have a look at is very small here but I'm sure you'll see is that the values of my data frame are going to change and the plot is going to update all in one go so let's hit shift and enter and you see the code ran and we have different set of numbers and the histogram has changed now try that for yourself or just watch again I'm going to do that and we see it runs and the plot changes immediately so that's the thing about Pluto notebooks that's that it is interactive and there's a state that's created all the time and all the cells get updated to that state if something has changed and a cell references some values in another cell so if I updated that cell with a thousand values that contains the thousand values my data frame is going to reference that cell because I set my variable my var 1 equal to those values and the plot has the data frame in it so those cells are somehow connected I mean that's just logical and things update so that's very different from a Jupiter notebook where you have to really keep track of making changes and then making sure that if you generated some results from those values or some plots and graphs from those that you should rerun those cells manually so that they would update as well but here in the Pluto notebook those are done at the same time so let's just do it one more time and shift and enter and the data frame updated and then the plot updated itself as well so that is very neat so in short this is a Pluto notebook it's a lovely coding environment just for you to experiment or to just to explore your data lovely for data exploration and as much as that you have this interactivity in this live update so I hope you enjoyed this video give Pluto a try there's some wonderful environments of course the Jupiter notebook is a fantastic coding environment you can also use Juno which is installation on top of Atom the IDE you can use Visual Studio Code to write your code and now you can also use Pluto fantastic coding environment explore all of these and enjoy using Julia